Created
June 9, 2011 07:46
-
-
Save bnoguchi/1016268 to your computer and use it in GitHub Desktop.
Example of how to correctly do mongoose GH-228
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; | |
var db = mongoose.connect('mongodb://localhost/test'); | |
var TestEmbedSchema = new Schema({ | |
name : { type: String, index: true} | |
}); | |
var TestEmbed = mongoose.model('TestEmbed', TestEmbedSchema); | |
var TestSchema = new Schema({ | |
name : { type: String, index: true} | |
, tesTestEmbeded : { | |
name: { type: String, index: true } | |
} | |
, tesTestEmbededarray: [TestEmbedSchema] | |
}); | |
var Test = mongoose.model('TestSchema', TestSchema); | |
var test = new Test(); | |
test.name = 'hellomodel'; | |
test.tesTestEmbeded = { name: 'embedded' }; | |
test.save(function(err){ | |
Test.findOne({name:'hellomodel'}, function(err, item) { | |
item.tesTestEmbededarray.push(item.tesTestEmbeded.toObject()); | |
item.tesTestEmbeded = { name: 'embedded2' }; | |
item.save(function(err){ | |
console.log(err); | |
console.log(item); | |
mongoose.disconnect(); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment