0
0
MongoDBquery~5 mins

Database and collection creation in MongoDB - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
How do you create a new database in MongoDB?
In MongoDB, you create a new database by switching to it using use databaseName. The database is created when you first store data in it.
Click to reveal answer
beginner
What command creates a new collection explicitly in MongoDB?
Use db.createCollection('collectionName') to create a new collection explicitly.
Click to reveal answer
beginner
True or False: In MongoDB, a database is created immediately when you switch to it with use.
False. The database is created only when you insert the first document into a collection within that database.
Click to reveal answer
beginner
What happens if you insert a document into a collection that does not exist in MongoDB?
MongoDB automatically creates the collection and the database (if not existing) when you insert the first document.
Click to reveal answer
intermediate
Explain the difference between creating a collection explicitly and implicitly in MongoDB.
Explicit creation uses db.createCollection(). Implicit creation happens automatically when you insert a document into a non-existing collection.
Click to reveal answer
Which command switches to a database named 'shop' in MongoDB?
Ause shop
Bdb.shop()
Ccreate database shop
Dswitch shop
How do you explicitly create a collection named 'products'?
Adb.products.insert()
Buse products
Ccreate collection products
Ddb.createCollection('products')
When is a MongoDB database actually created?
AWhen you run <code>use</code> command
BWhen you create a collection explicitly
CWhen you insert the first document
DWhen you start the MongoDB server
What happens if you insert a document into a non-existing collection?
ACollection and database are created automatically
BError is thrown
CNothing happens
DYou must create collection first
Which of these is NOT a way to create a collection in MongoDB?
AUsing db.createCollection()
BUsing SQL CREATE TABLE command
CInserting a document into a new collection
DSwitching to a new database with use command
Describe the process of creating a new database and collection in MongoDB.
Think about what happens when you insert data.
You got /3 concepts.
    Explain the difference between implicit and explicit collection creation in MongoDB.
    One is manual, the other automatic.
    You got /3 concepts.