0
0
Expressframework~10 mins

Creating documents in Express - Interactive Practice

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

Complete the code to create a new document in Express using Mongoose.

Express
const newUser = new User({ name: 'Alice', age: 25 });
newUser.[1]();
Drag options to blanks, or click blank then click option'
Adelete
Bsave
Cupdate
Dfind
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'find' instead of 'save' to create a document.
Trying to update or delete before saving the document.
2fill in blank
medium

Complete the code to create and save a new product document asynchronously.

Express
async function addProduct() {
  const product = new Product({ name: 'Book', price: 15 });
  await product.[1]();
}
Drag options to blanks, or click blank then click option'
AupdateOne
Bremove
CfindOne
Dsave
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'remove' which deletes documents.
Using 'findOne' which searches documents instead of saving.
3fill in blank
hard

Fix the error in the code to correctly create a new user document.

Express
const user = new User({ username: 'john' });
user.[1]();
Drag options to blanks, or click blank then click option'
Asave
Bcreate
Cfind
Ddelete
Attempts:
3 left
💡 Hint
Common Mistakes
Calling 'create' on an instance instead of the model.
Not using 'new' keyword to create the document.
4fill in blank
hard

Fill both blanks to create and save a new blog post document with a title and content.

Express
const post = new Post({ title: [1], content: [2] });
await post.save();
Drag options to blanks, or click blank then click option'
A'My Day'
B'Hello World'
C'This is my first post.'
D'Sample content'
Attempts:
3 left
💡 Hint
Common Mistakes
Using unquoted strings causing syntax errors.
Mixing up title and content values.
5fill in blank
hard

Fill all three blanks to create a new comment document and save it asynchronously.

Express
async function addComment() {
  const comment = new Comment({
    author: [1],
    text: [2],
    date: [3]
  });
  await comment.save();
}
Drag options to blanks, or click blank then click option'
A'Alice'
B'Great post!'
Cnew Date()
D'2023-01-01'
Attempts:
3 left
💡 Hint
Common Mistakes
Using date as a string instead of a Date object.
Forgetting quotes around author or text.