mongoose how to reference an object code example

Example 1: mongodb populate document

Story.
  findOne({ title: 'Casino Royale' }).
  populate('author').
  exec(function (err, story) {
    if (err) return handleError(err);
    console.log('The author is %s', story.author.name);
    // prints "The author is Ian Fleming"
  });

Example 2: mongo object references in mongoose

User = new Schema({
    places:[{type: Schema.Types.ObjectId, ref:'Place'}],
    shouts:[{type: Schema.Types.ObjectId, ref:'Shout'}]
});
Place = new Schema({
    name:String,
    description:String,
});
Shout = new Schema({
    content:String,
});

Tags:

Misc Example