0
0
Expressframework~10 mins

Mongoose ODM setup 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 Mongoose in an Express app.

Express
const mongoose = require('[1]');
Drag options to blanks, or click blank then click option'
Amongoose
Bexpress
Cmongodb
Dbody-parser
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'express' instead of 'mongoose' in require.
Using 'mongodb' which is the native driver, not Mongoose.
2fill in blank
medium

Complete the code to connect Mongoose to a MongoDB database.

Express
mongoose.[1]('mongodb://localhost:27017/mydb');
Drag options to blanks, or click blank then click option'
AcreateConnection
Bconnect
Copen
Dstart
Attempts:
3 left
💡 Hint
Common Mistakes
Using createConnection instead of connect.
Using non-existent methods like open or start.
3fill in blank
hard

Fix the error in defining a Mongoose schema.

Express
const userSchema = new mongoose.Schema({ name: [1] });
Drag options to blanks, or click blank then click option'
A{ type: }
Btype: String
CString
D{ type: String }
Attempts:
3 left
💡 Hint
Common Mistakes
Using just String without { type: String }.
Leaving type empty or incomplete.
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
CUserSchema
DuserModel
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing model name with schema variable.
Exporting the schema instead of the model.
5fill in blank
hard

Fill all three blanks to define a schema with a required email field and create a model.

Express
const [1] = new mongoose.Schema({
  email: { type: String, [2]: true }
});
const [3] = mongoose.model('Contact', [1]);
Drag options to blanks, or click blank then click option'
AcontactSchema
Brequired
CContact
DemailSchema
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names for schema or model.
Using require instead of required.