Skip to content

Instantly share code, notes, and snippets.

@bhelx

bhelx/test.js

Created Nov 25, 2012
Embed
What would you like to do?
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
You can’t perform that action at this time.