Guest User

Untitled

a guest
Oct 16th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1.  
  2. var mongoose = require('./../mongoose');
  3. var Schema = mongoose.Schema;
  4. mongoose.connect('localhost', 'testing_10777676');
  5. mongoose.connection.on('error', function () {
  6. console.error(arguments);
  7. });
  8.  
  9. var schema = new Schema({
  10. name: String
  11. });
  12. var par = new Schema({ child: [schema ]});
  13.  
  14. var A = mongoose.model('A', par);
  15.  
  16. mongoose.connection.on('open', function () {
  17. var a = new A({ child: [{ name: '10777676'}] });
  18. a.save(function (err, a) {
  19. if (err) return console.error(err.stack||err);
  20.  
  21. A.findById(a, function (err, doc) {
  22. if (err) console.error(err.stack||err);
  23.  
  24. doc.child.id(doc.child[0]._id).remove();
  25. mongoose.set('debug', true);
  26. doc.save(function (err) {
  27. if (err) console.error(err);
  28.  
  29. A.findById(a, function (err, doc) {
  30. if (err) console.error(err);
  31. console.error('after removing', doc);
  32. mongoose.connection.db.dropDatabase(function () {
  33. mongoose.connection.close();
  34. });
  35. });
  36. });
  37.  
  38. });
  39. })
  40. });
Add Comment
Please, Sign In to add comment