0
0
Expressframework~10 mins

Population for references in Express - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the Mongoose library.

Express
const mongoose = require('[1]');
Drag options to blanks, or click blank then click option'
Acors
Bmongoose
Cbody-parser
Dexpress
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'express' instead of 'mongoose'.
Forgetting to import Mongoose before using it.
2fill in blank
medium

Complete the code to define a Mongoose schema for a User with a name field.

Express
const userSchema = new mongoose.Schema({ name: { type: [1], required: true } });
Drag options to blanks, or click blank then click option'
AString
BNumber
CBoolean
DDate
Attempts:
3 left
💡 Hint
Common Mistakes
Using Number or Boolean for text fields.
Forgetting to set the type property.
3fill in blank
hard

Fix the error in the code to populate the 'author' reference in a Post model query.

Express
Post.find().populate('[1]').exec((err, posts) => { console.log(posts); });
Drag options to blanks, or click blank then click option'
Acomments
Btags
Cauthor
Dlikes
Attempts:
3 left
💡 Hint
Common Mistakes
Populating a field that is not a reference.
Using the wrong field name in populate.
4fill in blank
hard

Fill both blanks to create a Mongoose model and export it.

Express
const [1] = mongoose.model('User', [2]);
module.exports = [1];
Drag options to blanks, or click blank then click option'
AUser
BuserSchema
CpostSchema
DPost
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing model and schema names.
Forgetting to export the model.
5fill in blank
hard

Fill all three blanks to query posts and populate both 'author' and 'comments' references.

Express
Post.find().populate('[1]').populate('[2]').exec((err, [3]) => {
  if (err) return console.error(err);
  console.log([3]);
});
Drag options to blanks, or click blank then click option'
Aauthor
Bcomments
Cposts
Dusers
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong field names in populate.
Mismatching the callback variable name.