Skip to content

Instantly share code, notes, and snippets.

@bnoguchi
Created April 26, 2011 21:24
Show Gist options
  • Save bnoguchi/943199 to your computer and use it in GitHub Desktop.
Save bnoguchi/943199 to your computer and use it in GitHub Desktop.
Reply to mongoose GH-334
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