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. Graph Database
B. NoSQL Document Database
C. Key-Value Store
D. Relational Database Management System (RDBMS)

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

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

3 Which format does MongoDB use to store data internally?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

11 Which command deletes the currently selected database?

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

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

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

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

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

14 Which method retrieves all documents from a collection?

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

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

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

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

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

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

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

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

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

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

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

20 What is the default TCP port for MongoDB?

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

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

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

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

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

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

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

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.createSchema()
B. new mongoose.Schema()
C. mongoose.define()
D. new mongoose.Table()

26 What is a Mongoose 'Model'?

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

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

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

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

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

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

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

30 Which Mongoose method finds a document by its _id?

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

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

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

32 How do you connect to MongoDB using Mongoose?

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

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

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

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. Sets the field to the current date if no value is provided.
B. Forces the user to enter the current date.
C. Throws an error if the date is not now.
D. Updates the date every time the document is accessed.

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

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

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

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

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

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

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

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

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

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

41 In Node.js, most MongoDB operations are:

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

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 makes the field read-only.
B. It creates a unique index to prevent duplicate values for that field.
C. It ensures the field cannot be null.
D. It hides the field from queries.

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

A. removeById()
B. findByIdAndRemove() (or findByIdAndDelete)
C. deleteId()
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. Both use dynamic schemas.
D. SQL has rigid schemas; NoSQL has dynamic/flexible schemas.

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

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

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

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

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

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

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

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

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

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