wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

MongoDB Quiz

Total questions: 35

Worksheet time: 18mins

Name
Class
Date
1.

Which command is used to show all databases in MongoDB?

a)

db.show()

b)

show dbs

c)

show databases

d)

dbs.show()

2.

What command switches to a database named studentDB?

a)

switch studentDB

b)

use studentDB

c)

db studentDB

d)

select studentDB

3.

Which command displays all collections in the current database?

a)

show collections

b)

show tables

c)

db.showCollections()

d)

show all

4.

How do you insert one document into a collection named students?

a)

students.insert({name:"Ali"})

b)

db.students.insertOne({name:"Ali"})

c)

insert students({name:"Ali"})

d)

db.students.add({name:"Ali"})

5.

Which is a valid data type in MongoDB?

a)

String

b)

Integer

c)

Boolean

d)

All of the above

6.

MongoDB stores data in which format?

a)

XML

b)

BSON

c)

CSV

d)

YAML

7.

Which is the correct command to delete a collection?

a)

drop collection students

b)

db.students.remove()

c)

db.students.delete()

d)

db.students.drop()

8.

To update a field in a document, we use which operator?

a)

$update

b)

$modify

c)

$set

d)

$change

9.

To delete a specific student using email, which command is used?

a)

db.students.remove({email: "a@a.com"})

b)

db.students.delete({email: "a@a.com"})

c)

remove db.students(email="a@a.com")

d)

db.students.drop(email: "a@a.com")

10.

MongoDB is a:

a)

Relational DBMS

b)

NoSQL Document DB

c)

Graph Database

d)

SQL-based system

11.

Which operator is used to filter documents where age is greater than 25?

a)

$gt: 25

b)

$lt: 25

c)

age > 25

d)

>25

12.

Find all products with rating greater than 4:

a)

db.products.find({rating > 4})

b)

db.products.find({rating: {$gt: 4}})

c)

db.products.where(rating > 4)

d)

db.products.get({rating: $gt 4})

13.

Find all students enrolled in the "Java" course:

a)

db.students.find({course: "Java"})

b)

db.students.search({course: "Java"})

c)

db.students.filter({course = "Java"})

d)

db.students.get({course = "Java"})

14.

Which query returns documents where stock is less than 10?

a)

db.products.find({stock < 10})

b)

db.products.find(stock: {$lt: 10})

c)

db.products.find({stock: {$lt: 10}})

d)

db.products.where(stock < 10)

15.

Which query returns all movies released after 2020?

a)

db.movies.find({releaseYear > 2020})

b)

db.movies.find({releaseYear: {$gt: 2020}})

c)

db.movies.where(releaseYear > 2020)

d)

db.movies.get({releaseYear > 2020})

16.

To find all documents in a collection, use:

a)

db.collection.getAll()

b)

db.collection.all()

c)

db.collection.find()

d)

db.collection.show()

17.

Which command updates stock of a product named "TV" to 20?

a)

db.products.update({name:"TV"}, {$stock: 20})

b)

db.products.updateOne({name:"TV"}, {$set: {stock: 20}})

c)

db.products.set({stock: 20})

d)

db.products.modify({stock=20})

18.

Which query finds documents with rating ≥ 4.5?

a)

$gte: 4.5

b)

$gt= 4.5

c)

$gte = 4.5

d)

$more: 4.5

19.

Which method updates multiple documents?

a)

updateOne()

b)

updateMany()

c)

modify()

d)

setMany()

20.

To delete all products priced above ₹50,000, use:

a)

db.products.delete({price: {$gt: 50000}})

b)

db.products.remove({price: {$gt: 50000}})

c)

db.products.drop({price: {$gt: 50000}})

d)

db.products.find(price > 50000).remove()

21.

____ studentDB is used to switch database.

a)

use

b)

select

c)

choose

d)

db

22.

In MongoDB, collections are like ____ in relational databases.

a)

columns

b)

rows

c)

tables

d)

schemas

23.

db.students.____({name: "Ahmed"}) is used to add a document.

a)

add

b)

insertOne

c)

write

d)

make

24.

To increase age by 1 for all students, we use operator ____.

a)

$add

b)

$inc

c)

$plus

d)

$more

25.

To update only one matching document, use ____ method.

a)

updateAll

b)

updateOne

c)

modify

d)

changeOne

26.

MongoDB's shell language is based on ____ syntax.

a)

Java

b)

Python

c)

JavaScript

d)

SQL

27.

In MongoDB, _id field is a ____ identifier for documents.

a)

static

b)

optional

c)

required

d)

unique

28.

To view a single document, use ____.

a)

find()

b)

findOne()

c)

get()

d)

show()

29.

To list all databases, type ____.

a)

show databases

b)

list dbs

c)

show all

d)

list all

30.

The default port MongoDB uses is ____.

a)

3306

b)

8080

c)

27017

d)

1521

31.

Which query returns all books where author's country is "India"?

a)

db.books.find({"author.country": "India"})

b)

db.books.find({author.country: "India"})

c)

db.books.get(author.country = "India")

d)

db.books.find("author.country" = "India")

32.

Which operator is used to match documents that have a field?

a)

$exists

b)

$has

c)

$contain

d)

$present

33.

Which method returns the first matching document?

a)

find()

b)

findFirst()

c)

findOne()

d)

getOne()

34.

What is the command to update genre of a movie titled "Avatar"?

a)

db.movies.update({title: "Avatar"}, {$set: {genre: "Sci-Fi"}})

b)

db.movies.modify({title: "Avatar"}, {genre: "Sci-Fi"})

c)

db.movies.set(title: "Avatar", genre: "Sci-Fi")

d)

db.movies.replace({title: "Avatar"}, {genre: "Sci-Fi"})

35.

What will this query do: db.books.find({pages: {$lte: 300}})?

a)

Returns books with more than 300 pages

b)

Returns books with exactly 300 pages

c)

Returns books with less than or equal to 300 pages

d)

Deletes books with less than 300 pages