O'Reilly logo

Mongoose for Application Development by Simon Holmes

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Subdocuments

Subdocuments are very similar to the ordinary documents we have been using so far. They are individual documents with their own schema. The big difference is that subdocuments are documents that are stored within a parent document, instead of a MongoDB collection of their own.

Perhaps an example will demonstrate this best. In our MongoosePM application, tasks are currently lacking in functionality as tasks for a given project is just a string. It would be better if a task had a distinct schema like the following:

var taskSchema = new mongoose.Schema({ taskName: { type: String, required: true, validate: validateLength }, taskDesc: String, createdOn: { type: Date, default: Date.now }, createdBy: { type: mongoose.Schema.Types.ObjectId, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required