0
0
Expressframework~10 mins

Defining 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 the Mongoose library.

Express
const mongoose = require([1]);
Drag options to blanks, or click blank then click option'
A"fs"
B"express"
C"mongoose"
D"http"
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'express' instead of 'mongoose'.
Forgetting the quotes around the package name.
2fill in blank
medium

Complete the code to define a new Mongoose schema.

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

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

Express
const User = mongoose.model('User', [1]);
Drag options to blanks, or click blank then click option'
AuserSchema
BuserSchema()
CUserSchema
DUser
Attempts:
3 left
💡 Hint
Common Mistakes
Calling userSchema as a function.
Using capitalized 'UserSchema' when the variable is lowercase.
4fill in blank
hard

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

Express
const productSchema = new mongoose.[1]({ name: { type: String, [2]: true }, price: Number });
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.
Using 'Model' instead of 'Schema' for schema definition.
5fill in blank
hard

Fill all three blanks to create and export a Mongoose model named 'Order' with a schema having a date and total fields.

Express
const orderSchema = new mongoose.[1]({ date: Date, total: Number });
const Order = mongoose.[2]('Order', [3]);
module.exports = Order;
Drag options to blanks, or click blank then click option'
ASchema
Bmodel
CorderSchema
DDocument
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Document' instead of 'Schema'.
Passing the model name instead of the schema to mongoose.model.