Created
April 26, 2011 21:24
-
-
Save bnoguchi/943199 to your computer and use it in GitHub Desktop.
Reply to mongoose GH-334
This file contains 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') | |
, Schema = mongoose.Schema | |
, assert = require('assert'); | |
var subSchema = new Schema({ | |
name : String , | |
subObj : { subName : String } | |
}); | |
var schema = new Schema ({ name : String , arrData : [ subSchema] }); | |
var db = mongoose.createConnection('mongodb://localhost/bugs'); | |
mongoose.model('model' , schema); | |
var model = db.model('model'); | |
var instance = new model(); | |
instance.set( { name : 'name-value' , arrData : [ { name : 'arrName1' , subObj : { subName : 'subName1' } } ] }); | |
instance.save(function(err) { | |
model.findById(instance.id, function(err, doc) { | |
doc.arrData[0].set('subObj' , { subName : 'modified subName' }); | |
doc.save(function(err) { | |
if (err) throw err; | |
model.findById(instance.id, function (err, doc) { | |
console.log("SUCCESS"); | |
assert.equal(doc.arrData[0].subObj.subName, 'modified subName'); | |
db.close(); | |
}); | |
}); | |
}); | |
}); | |
// => SUCCESS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment