Complete the code to create a new database named 'school'.
use [1]The use command switches to or creates the database named 'school'.
Complete the code to create a collection named 'students' in the current database.
db.[1].insertOne({name: 'Alice', age: 20})
In MongoDB, inserting a document into a collection creates the collection if it does not exist. Here, 'students' is the collection name.
Fix the error in the code to create a collection named 'books'.
db.createCollection('[1]')
create() method on a collection.The correct method to create a collection explicitly is db.createCollection('books').
Fill both blanks to explicitly create a collection named 'employees' in the 'company' database.
use [1] db.[2]('employees')
First, switch to the 'company' database using use company. Then create the collection 'employees' explicitly with db.createCollection('employees'). Here, the blank for the method is createCollection.
Fill all three blanks to create a database 'library', create a collection 'books', and insert a document with title '1984'.
use [1] db.[2].[3]({title: '1984'})
insertMany when only one document is inserted.First, switch to the 'library' database. Then use the 'books' collection. Finally, insert one document with insertOne method.