mongoose populate field without ref option mongoose populate field without ref option mongodb mongodb

mongoose populate field without ref option


Conversation.find().populate('creator', null, 'User2').exec(callback)

The docs aren't clear. Will update soon.

Also, the syntax for this will be simpler in v3.6.


As of 27th March 2019 the way to do so is:

1) Setting the field you want to populate as a ObjectId without providing a ref.

var eventSchema = new Schema({  name: String,  // The id of the corresponding conversation  // Notice there's no ref here!  conversation: ObjectId});

2) While making the query pass the model for the schema along with the query:

Event.  find().  populate({ path: 'conversation', model: Conversation }).  exec(function(error, docs) { /* ... */ });

REF: https://mongoosejs.com/docs/populate.html#cross-db-populate