Unit 4: Getting Started with MongoDB & Introduction to Mongoose - Practice Quiz

INT222 — Advanced Web Development 50 Questions
0 Correct 0 Wrong 50 Left
0/50

1 What type of database is MongoDB classified as?

A. Key-Value Store
B. Graph Database
C. Relational Database Management System (RDBMS)
D. NoSQL Document Database

2 In MongoDB, what is the equivalent of a 'Table' in an RDBMS?

A. Field
B. Document
C. Collection
D. Cluster

3 Which format does MongoDB use to store data internally?

A. YAML
B. XML
C. BSON
D. JSON

4 What is the default field added to every MongoDB document to act as a primary key?

A. id
B. key
C. primary_id
D. _id

5 Which command is used in the MongoDB shell to switch to a specific database?

A. db database_name
B. switch database_name
C. connect database_name
D. use database_name

6 What happens if you switch to a database that does not exist and insert data?

A. It throws an error.
B. MongoDB creates the database automatically.
C. It asks for confirmation to create it.
D. The data is discarded.

7 Which command displays the list of existing databases in the shell?

A. display dbs
B. show databases all
C. list databases
D. show dbs

8 In MongoDB, a 'Row' in an RDBMS is equivalent to a:

A. Table
B. Collection
C. Field
D. Document

9 Which command is used to explicitly create a collection with specific options?

A. db.newCollection('name')
B. db.createCollection('name')
C. db.collection.create('name')
D. db.insertCollection('name')

10 How do you delete a collection named 'users' in the MongoDB shell?

A. db.users.drop()
B. db.users.delete()
C. db.dropCollection('users')
D. db.users.remove()

11 Which command deletes the currently selected database?

A. db.removeDatabase()
B. db.deleteDatabase()
C. db.dropDatabase()
D. delete db

12 Which method is used to insert a single document into a collection?

A. db.collection.insertOne()
B. db.collection.addOne()
C. db.collection.put()
D. db.collection.push()

13 What is the correct syntax to insert multiple documents at once?

A. db.collection.insertMany({...}, {...})
B. db.collection.insertAll([{...}, {...}])
C. db.collection.insertMany([{...}, {...}])
D. db.collection.addMany([{...}, {...}])

14 Which method retrieves all documents from a collection?

A. db.collection.getAll()
B. db.collection.select(*)
C. db.collection.find()
D. db.collection.search()

15 How do you format the output of a find() query to be more readable in the shell?

A. db.collection.find().pretty()
B. db.collection.find().clean()
C. db.collection.find().format()
D. db.collection.find().beautify()

16 Which operator is used to specify fields to include or exclude in a query result (Projection)?

A. { field: 1 }
B. SELECT field
C. WHERE field
D. SHOW field

17 Which update operator is used to modify the value of a specific field?

A. $modify
B. $set
C. $update
D. $change

18 What is the difference between updateOne() and updateMany()?

A. updateMany is deprecated.
B. They function identically.
C. updateOne updates the last match; updateMany updates all matches.
D. updateOne updates the first match; updateMany updates all matches.

19 Which method is used to remove a document from a collection?

A. db.collection.clear()
B. db.collection.deleteOne()
C. db.collection.erase()
D. db.collection.zap()

20 What is the default TCP port for MongoDB?

A. 3306
B. 8080
C. 27017
D. 5432

21 In a MongoDB connection string mongodb://localhost:27017/mydb, what does mydb represent?

A. The collection name
B. The database name
C. The server name
D. The username

22 What does ODM stand for in the context of Mongoose?

A. Object Document Mapper
B. Online Database Manager
C. Object Data Model
D. Object Database Method

23 Which command installs Mongoose in a Node.js project?

A. npm add mongoose-db
B. node install mongoose
C. npm install mongo
D. npm install mongoose

24 In Mongoose, what is a 'Schema'?

A. A direct connection to the database.
B. A query builder.
C. A configuration object defining the structure and rules of data.
D. The actual document stored in MongoDB.

25 Which function is used to create a Mongoose Schema?

A. mongoose.define()
B. new mongoose.Table()
C. mongoose.createSchema()
D. new mongoose.Schema()

26 What is a Mongoose 'Model'?

A. A prototype of the database server.
B. A compiled version of the Schema used to interact with the database.
C. A type of validation rule.
D. A JSON file storing data.

27 How do you define a model named 'User' based on a schema userSchema?

A. mongoose.createModel('User', userSchema)
B. new mongoose.Model('User', userSchema)
C. mongoose.model('User', userSchema)
D. userSchema.model('User')

28 In a Mongoose Schema, how do you ensure a field is mandatory?

A. mandatory: true
B. mustHave: true
C. allowNull: false
D. required: true

29 Which method is used to save a new document instance created via Mongoose?

A. document.insert()
B. document.save()
C. document.create()
D. document.push()

30 Which Mongoose method finds a document by its _id?

A. Model.findById()
B. Model.findId()
C. Model.get()
D. Model.findOneId()

31 What data type should be defined in a Mongoose schema for an age field?

A. Int
B. Number
C. Float
D. Integer

32 How do you connect to MongoDB using Mongoose?

A. mongoose.start(connectionString)
B. mongoose.db.connect(connectionString)
C. mongoose.open(connectionString)
D. mongoose.connect(connectionString)

33 Which query operator is used in MongoDB to find values 'greater than' a specific value?

A. $high
B. $lt
C. $gte
D. $gt

34 What is the purpose of Model.create() in Mongoose?

A. To create a database index.
B. To instantiate and save a document in one step.
C. To create a collection only.
D. To define a schema.

35 When defining a schema, what does default: Date.now do?

A. Forces the user to enter the current date.
B. Updates the date every time the document is accessed.
C. Throws an error if the date is not now.
D. Sets the field to the current date if no value is provided.

36 Which Mongoose method is used to find a document by ID and update it?

A. findByIdAndUpdate
B. updateById
C. saveById
D. findAndModify

37 In the MongoDB shell, what does db refer to?

A. The admin user
B. The database server
C. The current database context
D. The collection list

38 What is the result of db.collection.find({ age: 25 })?

A. Updates documents where age is 25.
B. Returns the first document where age is 25.
C. Deletes documents where age is 25.
D. Returns all documents where age is 25.

39 Which of the following is NOT a valid BSON data type?

A. Table
B. Boolean
C. Array
D. String

40 What does the limit() method do in a MongoDB query?

A. Stops the query after a specific time.
B. Specifies the maximum number of documents to return.
C. Limits the number of fields returned.
D. Restricts the size of the document.

41 In Node.js, most MongoDB operations are:

A. Linear
B. Blocking
C. Synchronous
D. Asynchronous

42 Which Mongoose schema option adds createdAt and updatedAt fields automatically?

A. { time: true }
B. { stamps: true }
C. { dates: true }
D. { timestamps: true }

43 What is the purpose of the unique: true option in a Mongoose schema field?

A. It creates a unique index to prevent duplicate values for that field.
B. It ensures the field cannot be null.
C. It hides the field from queries.
D. It makes the field read-only.

44 Which method effectively removes a document by ID in Mongoose?

A. deleteId()
B. findByIdAndRemove() (or findByIdAndDelete)
C. removeById()
D. dropId()

45 What is the structural difference between SQL and NoSQL regarding schemas?

A. Both use rigid schemas.
B. SQL has dynamic schemas; NoSQL has rigid schemas.
C. SQL has rigid schemas; NoSQL has dynamic/flexible schemas.
D. Both use dynamic schemas.

46 To perform an update that increments a number field by 1, which operator is used?

A. $inc
B. $add
C. $sum
D. $plus

47 What does the findOne method return if no document matches?

A. An error
B. An empty array []
C. null
D. undefined

48 Which file usually contains the database connection logic in a Node/Express app?

A. package.json
B. style.css
C. db.js or app.js
D. index.html

49 In a Mongoose query, how do you specify that you want to sort the results in descending order?

A. .order('down')
B. .sort({ field: 'desc' })
C. .sort({ field: 1 })
D. .sort({ field: -1 })

50 If you want to define an array of strings in a Mongoose schema, what is the correct syntax?

A. tags: [String]
B. tags: Array<String>
C. tags: { type: Array, contains: String }
D. tags: String[]