NEW
Font size
WorksheetsMongoDB Quiz
Total questions: 35
Worksheet time: 18mins
Which command is used to show all databases in MongoDB?
db.show()
show dbs
show databases
dbs.show()
What command switches to a database named studentDB?
switch studentDB
use studentDB
db studentDB
select studentDB
Which command displays all collections in the current database?
show collections
show tables
db.showCollections()
show all
How do you insert one document into a collection named students?
students.insert({name:"Ali"})
db.students.insertOne({name:"Ali"})
insert students({name:"Ali"})
db.students.add({name:"Ali"})
Which is a valid data type in MongoDB?
String
Integer
Boolean
All of the above
MongoDB stores data in which format?
XML
BSON
CSV
YAML
Which is the correct command to delete a collection?
drop collection students
db.students.remove()
db.students.delete()
db.students.drop()
To update a field in a document, we use which operator?
$update
$modify
$set
$change
To delete a specific student using email, which command is used?
db.students.remove({email: "a@a.com"})
db.students.delete({email: "a@a.com"})
remove db.students(email="a@a.com")
db.students.drop(email: "a@a.com")
MongoDB is a:
Relational DBMS
NoSQL Document DB
Graph Database
SQL-based system
Which operator is used to filter documents where age is greater than 25?
$gt: 25
$lt: 25
age > 25
>25
Find all products with rating greater than 4:
db.products.find({rating > 4})
db.products.find({rating: {$gt: 4}})
db.products.where(rating > 4)
db.products.get({rating: $gt 4})
Find all students enrolled in the "Java" course:
db.students.find({course: "Java"})
db.students.search({course: "Java"})
db.students.filter({course = "Java"})
db.students.get({course = "Java"})
Which query returns documents where stock is less than 10?
db.products.find({stock < 10})
db.products.find(stock: {$lt: 10})
db.products.find({stock: {$lt: 10}})
db.products.where(stock < 10)
Which query returns all movies released after 2020?
db.movies.find({releaseYear > 2020})
db.movies.find({releaseYear: {$gt: 2020}})
db.movies.where(releaseYear > 2020)
db.movies.get({releaseYear > 2020})
To find all documents in a collection, use:
db.collection.getAll()
db.collection.all()
db.collection.find()
db.collection.show()
Which command updates stock of a product named "TV" to 20?
db.products.update({name:"TV"}, {$stock: 20})
db.products.updateOne({name:"TV"}, {$set: {stock: 20}})
db.products.set({stock: 20})
db.products.modify({stock=20})
Which query finds documents with rating ≥ 4.5?
$gte: 4.5
$gt= 4.5
$gte = 4.5
$more: 4.5
Which method updates multiple documents?
updateOne()
updateMany()
modify()
setMany()
To delete all products priced above ₹50,000, use:
db.products.delete({price: {$gt: 50000}})
db.products.remove({price: {$gt: 50000}})
db.products.drop({price: {$gt: 50000}})
db.products.find(price > 50000).remove()
____ studentDB is used to switch database.
use
select
choose
db
In MongoDB, collections are like ____ in relational databases.
columns
rows
tables
schemas
db.students.____({name: "Ahmed"}) is used to add a document.
add
insertOne
write
make
To increase age by 1 for all students, we use operator ____.
$add
$inc
$plus
$more
To update only one matching document, use ____ method.
updateAll
updateOne
modify
changeOne
MongoDB's shell language is based on ____ syntax.
Java
Python
JavaScript
SQL
In MongoDB, _id field is a ____ identifier for documents.
static
optional
required
unique
To view a single document, use ____.
find()
findOne()
get()
show()
To list all databases, type ____.
show databases
list dbs
show all
list all
The default port MongoDB uses is ____.
3306
8080
27017
1521
Which query returns all books where author's country is "India"?
db.books.find({"author.country": "India"})
db.books.find({author.country: "India"})
db.books.get(author.country = "India")
db.books.find("author.country" = "India")
Which operator is used to match documents that have a field?
$exists
$has
$contain
$present
Which method returns the first matching document?
find()
findFirst()
findOne()
getOne()
What is the command to update genre of a movie titled "Avatar"?
db.movies.update({title: "Avatar"}, {$set: {genre: "Sci-Fi"}})
db.movies.modify({title: "Avatar"}, {genre: "Sci-Fi"})
db.movies.set(title: "Avatar", genre: "Sci-Fi")
db.movies.replace({title: "Avatar"}, {genre: "Sci-Fi"})
What will this query do: db.books.find({pages: {$lte: 300}})?
Returns books with more than 300 pages
Returns books with exactly 300 pages
Returns books with less than or equal to 300 pages
Deletes books with less than 300 pages
