Skip to content

Instantly share code, notes, and snippets.

@sebm
Created June 29, 2011 22:37
Show Gist options
  • Save sebm/1055180 to your computer and use it in GitHub Desktop.
Save sebm/1055180 to your computer and use it in GitHub Desktop.
A problem I'm encountering deleting embedded documents using Mongoose
node.js:134
throw e; // process.nextTick error, or 'error' event on first tick
^
TypeError: Object #<Object> has no method 'remove'
at /Users/sebastian/japes/mongotest/mongotest.js:34:22
at /Users/sebastian/japes/mongotest/node_modules/mongoose/lib/mongoose/query.js:660:22
at model.init (/Users/sebastian/japes/mongotest/node_modules/mongoose/lib/mongoose/document.js:147:5)
at /Users/sebastian/japes/mongotest/node_modules/mongoose/lib/mongoose/query.js:658:16
at /Users/sebastian/japes/mongotest/node_modules/mongoose/support/node-mongodb-native/lib/mongodb/cursor.js:130:9
at /Users/sebastian/japes/mongotest/node_modules/mongoose/support/node-mongodb-native/lib/mongodb/cursor.js:176:11
at /Users/sebastian/japes/mongotest/node_modules/mongoose/support/node-mongodb-native/lib/mongodb/cursor.js:491:35
at [object Object].close (/Users/sebastian/japes/mongotest/node_modules/mongoose/support/node-mongodb-native/lib/mongodb/cursor.js:663:5)
at [object Object].nextObject (/Users/sebastian/japes/mongotest/node_modules/mongoose/support/node-mongodb-native/l%
var mongoose = require('mongoose');
var db = mongoose.connect('mongodb://localhost/sebtest');
var Schema = mongoose.Schema;
var StackSchema = new Schema({
name: String
,items: [StackItemSchema]
});
var StackItemSchema = new Schema({
blob: Number
});
var Stack = mongoose.model('Stack', StackSchema);
Stack.find({name:'The Stack'}, function (err, docs) {
var the_stack;
if (docs === undefined) {
the_stack = new Stack({name: 'The Stack'});
the_stack.save();
} else {
the_stack = docs[0];
}
console.log('Gonna add some items now');
the_stack.items.push({ blob:Math.random() });
the_stack.save();
console.log(the_stack.items[0])
the_stack.items[0].remove();
});
@bnoguchi
Copy link

bnoguchi commented Jul 1, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment