Created
June 29, 2011 22:37
-
-
Save sebm/1055180 to your computer and use it in GitHub Desktop.
A problem I'm encountering deleting embedded documents using Mongoose
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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% |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Please see https://gist.github.com/1059598