0
0
MongoDBquery~10 mins

Insert with arrays in MongoDB - Interactive Code Practice

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

Complete the code to insert a document with an array field into the collection.

MongoDB
db.students.insertOne({ name: "Alice", grades: [1] })
Drag options to blanks, or click blank then click option'
A[85, 90, 78]
B{85, 90, 78}
C"85, 90, 78"
D(85, 90, 78)
Attempts:
3 left
💡 Hint
Common Mistakes
Using curly braces {} which define objects, not arrays.
Using parentheses () which are not valid for arrays.
Using a string instead of an array.
2fill in blank
medium

Complete the code to insert multiple documents with arrays into the collection.

MongoDB
db.students.insertMany([ { name: "Bob", courses: [1] }, { name: "Carol", courses: ["Math", "Science"] } ])
Drag options to blanks, or click blank then click option'
A["History", "Art"]
B"History, Art"
C{"History", "Art"}
D("History", "Art")
Attempts:
3 left
💡 Hint
Common Mistakes
Using curly braces which define objects, not arrays.
Using parentheses which are invalid for arrays.
Using a string instead of an array.
3fill in blank
hard

Fix the error in the code to correctly insert a document with an array field.

MongoDB
db.students.insertOne({ name: "Dave", hobbies: [1] })
Drag options to blanks, or click blank then click option'
A"reading, swimming, hiking"
B{reading, swimming, hiking}
C(reading, swimming, hiking)
D["reading", "swimming", "hiking"]
Attempts:
3 left
💡 Hint
Common Mistakes
Using a single string instead of an array.
Using curly braces which define objects.
Using parentheses which are invalid for arrays.
4fill in blank
hard

Fill both blanks to insert a document with an array of objects representing books.

MongoDB
db.library.insertOne({ owner: "Eve", books: [ { title: [1], pages: [2] } ] })
Drag options to blanks, or click blank then click option'
A"The Hobbit"
B310
C"1984"
D250
Attempts:
3 left
💡 Hint
Common Mistakes
Putting numbers in quotes.
Not using quotes for strings.
Mixing up the order of title and pages.
5fill in blank
hard

Fill all three blanks to insert multiple documents with arrays of tags.

MongoDB
db.posts.insertMany([ { title: [1], tags: [2] }, { title: [3], tags: ["mongodb", "database"] } ])
Drag options to blanks, or click blank then click option'
A"Introduction to MongoDB"
B["nosql", "database"]
C"Advanced Queries"
D["queries", "performance"]
Attempts:
3 left
💡 Hint
Common Mistakes
Using objects instead of arrays for tags.
Not quoting the titles.
Using parentheses instead of square brackets.