Using Mongoose ref fields

Although MongoDB doesn't support joins, it supports the reference from a document to another document using a convention named DBRef. DBRef enables the reference from one document to another using a special field that contains the collection name and the document ObjectId field. Mongoose implements a similar behavior for supporting document referral using the ObjectID schema type and the use of the ref property. It also supports the population of the parent document with the child document when querying the database.

To understand this better, let's say you create another schema for blog posts called PostSchema. Because a user authors a blog post, PostSchema will contain an author field that will be populated by a User ...

Get MEAN Web Development - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.