Complete the code to import the Mongoose library.
const mongoose = require('[1]');
The Mongoose library is imported using require('mongoose') to work with MongoDB in Express.
Complete the code to define a Mongoose schema for a User with a name field.
const userSchema = new mongoose.Schema({ name: { type: [1], required: true } });The name field should be a string, so we use String as the type.
Fix the error in the code to populate the 'author' reference in a Post model query.
Post.find().populate('[1]').exec((err, posts) => { console.log(posts); });
To populate the referenced author data, use populate('author') matching the field name in the schema.
Fill both blanks to create a Mongoose model and export it.
const [1] = mongoose.model('User', [2]); module.exports = [1];
The model is named 'User' and uses the userSchema. Then it is exported with the same name.
Fill all three blanks to query posts and populate both 'author' and 'comments' references.
Post.find().populate('[1]').populate('[2]').exec((err, [3]) => { if (err) return console.error(err); console.log([3]); });
We populate both 'author' and 'comments' fields, then receive the results in the 'posts' variable.