MongoDB CRUD Operations Quiz Questions (original) (raw)
How do you create a database in MongoDB?
- db.createDatabase("")
What happens when you execute db.dropDatabase()?
- Deletes the current database and all its collections
- Deletes only empty collections from the database
- Removes only the database name but keeps the data
- Raises an error if the database is not empty
Which method is used to delete an entire collection in MongoDB?
- db.collection.removeAll()
- db.collection.deleteMany({})
- db.removeCollection("<collection_name>")
Which method allows inserting multiple documents into a MongoDB collection at once?
What does the updateOne() method do?
- Updates all documents that match the filter
- Updates the first matching document only
- Replaces an entire document
- Deletes a document before updating
How do you delete all documents that match a given filter in MongoDB?
How do you find a document with a specific _id in MongoDB?
- db.collection.findById(id)
- db.collection.find({ "_id": id })
- db.collection.getDocument(id)
- db.collection.findOne(id)
What does the findOneAndDelete() method do?
- Deletes all matching documents
- Finds and returns a document, then deletes it
- Deletes the first matching document without returning it
- Deletes a document after replacing it
How can you query for documents where a field is missing?
- { field: { $exists: false } }
- { field: { $notexists: true } }
- { field: { $missing: true } }
Which MongoDB method finds a document and updates it in one step?
There are 10 questions to complete.
Take a part in the ongoing discussion