DbRef with Mongoose - mongoose-dbref or populate? DbRef with Mongoose - mongoose-dbref or populate? mongodb mongodb

DbRef with Mongoose - mongoose-dbref or populate?


You only need to use an actual DBRef (and mongoose-dbref) for the case where a field can contain ObjectIds that reference documents in potentially more than one collection. A DBRef is a tuple of an ObjectId, a collection name, and an optional database name.

Mongoose ref: fields, however, contain just an ObjectId and it's the Mongoose schema that defines what one collection the ObjectIds reference.

So Mongoose ref: fields are more efficient and should always be used unless you need the multi-collection reference support that DBRef provides.