Skip to content

Instantly share code, notes, and snippets.

@bhelx
Created November 25, 2012 20:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bhelx/4145172 to your computer and use it in GitHub Desktop.
Save bhelx/4145172 to your computer and use it in GitHub Desktop.
Non _id document reference
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