September 2017
Intermediate to advanced
450 pages
11h 24m
English
Let's follow these steps to embed an author model as a sub-document into our blog post schema:
var mongoose = require('mongoose');var Schema = mongoose.Schema;var authorSchema = new Schema({ firstName: String, lastName: String, email: { type: String, required: true }});module.exports = mongoose.model('author', authorSchema);
...Author = require('./author');...var postSchema = new Schema({ title: { type: String, index: 'text', required: true, minlength: 5, maxlength: 64 }, content: { type: String, required: true, validate: [ markdownValidator, ...Read now
Unlock full access