Skip to content

Instantly share code, notes, and snippets.



Created Nov 25, 2012
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: }, function (err, m) {
Memory.findById('user').exec(function (err, memory) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment