Created
June 8, 2011 23:36
-
-
Save bnoguchi/1015725 to your computer and use it in GitHub Desktop.
GH-248 Working Example
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
// This shows that GH-248 is no longer relevant | |
var mongoose = require('mongoose') | |
, Schema = mongoose.Schema ; | |
mongoose.connect('mongodb://localhost/test'); | |
var EmbeddedDocSchema = new Schema({ | |
inner_label: String | |
}); | |
mongoose.model('EmbeddedDoc', EmbeddedDocSchema); | |
var EmbeddedDoc = mongoose.model('EmbeddedDoc'); | |
var ObservationSchema = new Schema({ | |
time_label: String, | |
embedded_docs: [EmbeddedDocSchema] | |
}); | |
mongoose.model('Observation', ObservationSchema); | |
var Observation = mongoose.model('Observation'); | |
var o = new Observation(); | |
var ed = new EmbeddedDoc(); | |
//o.embedded_docs.push({}); // THIS WORKS | |
o.embedded_docs.push(ed); // THIS ALSO WORKS | |
o.save(function(err){ | |
console.log("Save completed"); | |
Observation.findById(o.id, function (err, found) { | |
console.log(found); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment