Unit 4 - Practice Quiz

INT222

1 What type of database is MongoDB classified as?

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

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

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

3 Which format does MongoDB use to store data internally?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

11 Which command deletes the currently selected database?

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

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

A. db.collection.addOne()
B. db.collection.insertOne()
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.insertMany([{...}, {...}])
C. db.collection.addMany([{...}, {...}])
D. db.collection.insertAll([{...}, {...}])

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().format()
B. db.collection.find().pretty()
C. db.collection.find().beautify()
D. db.collection.find().clean()

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

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

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

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

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.erase()
B. db.collection.deleteOne()
C. db.collection.clear()
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 username
B. The collection name
C. The database name
D. The server name

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

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

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

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

24 In Mongoose, what is a 'Schema'?

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

25 Which function is used to create a Mongoose Schema?

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

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.model('User', userSchema)
B. mongoose.createModel('User', userSchema)
C. new 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. required: true
C. allowNull: false
D. mustHave: 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.findId()
B. Model.findById()
C. Model.findOneId()
D. Model.get()

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

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

32 How do you connect to MongoDB using Mongoose?

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

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

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

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

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

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. Updates the date every time the document is accessed.
D. Throws an error if the date is not now.

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

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

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

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

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

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

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

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

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

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

41 In Node.js, most MongoDB operations are:

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

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

A. { time: true }
B. { stamps: true }
C. { timestamps: true }
D. { dates: 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. findByIdAndRemove() (or findByIdAndDelete)
B. removeById()
C. deleteId()
D. dropId()

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

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

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

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

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

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

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

A. index.html
B. style.css
C. db.js or app.js
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: [String]
B. tags: { type: Array, contains: String }
C. tags: String[]
D. tags: Array<String>