Created
November 25, 2012 20:21
-
-
Save bhelx/4145172 to your computer and use it in GitHub Desktop.
Non _id document reference
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'); | |
var db = mongoose.createConnection('localhost', 'test'); | |
var UserSchema = mongoose.Schema({ | |
name: String, | |
phone: Number | |
}); | |
var MemorySchema = mongoose.Schema({ | |
user: { type: Number, ref: 'User' }, | |
text: String | |
}); | |
var User = db.model('User', UserSchema); | |
var Memory = db.model('Memory', MemorySchema); | |
User.create({ name: "bhelx", phone: 15556667788 }, function (err, u) { | |
Memory.create({ text: "Hello World!", user: u.phone }, function (err, m) { | |
Memory.findById(m.id).populate('user').exec(function (err, memory) { | |
console.log(err); | |
console.log(memory); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment