0
0
Expressframework~10 mins

Defining schemas and models 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
Cbody-parser
Dcors
Attempts:
3 left
💡 Hint
Common Mistakes
Importing 'express' instead of 'mongoose'.
Using a package unrelated to schemas like 'cors'.
2fill in blank
medium

Complete the code to create a new Mongoose schema.

Express
const userSchema = new mongoose.[1]({ name: String, age: Number });
Drag options to blanks, or click blank then click option'
ASchema
BCollection
CDocument
DModel
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Model' instead of 'Schema' to define structure.
Confusing 'Document' or 'Collection' with schema.
3fill in blank
hard

Fix the error in the code to create a model from a schema.

Express
const User = mongoose.model('[1]', userSchema);
Drag options to blanks, or click blank then click option'
AUserSchema
Busers
CuserSchema
DUser
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase or plural names like 'users'.
Passing the schema variable name instead of model name.
4fill in blank
hard

Fill both blanks to define a schema with a required string field and create a model.

Express
const productSchema = new mongoose.[1]({ title: { type: String, [2]: true } });
const Product = mongoose.model('Product', productSchema);
Drag options to blanks, or click blank then click option'
ASchema
Brequired
Cunique
Ddefault
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'unique' instead of 'required' for mandatory fields.
Confusing 'default' with 'required'.
5fill in blank
hard

Fill all three blanks to define a schema with a default number field, create a model, and export it.

Express
const orderSchema = new mongoose.[1]({ quantity: { type: Number, [2]: 1 } });
const Order = mongoose.model('[3]', orderSchema);
module.exports = Order;
Drag options to blanks, or click blank then click option'
ASchema
Bdefault
COrder
DModel
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Model' instead of 'Schema' for the first blank.
Using 'required' instead of 'default' for the second blank.
Using lowercase or plural model names.