Unit 4 - Practice Quiz

INT222 50 Questions
0 Correct 0 Wrong 50 Left
0/50

1 What type of database is MongoDB classified as?

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

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

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

3 Which format does MongoDB use to store data internally?

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

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

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

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

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

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

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

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

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

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

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

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

A. db.collection.create('name')
B. db.insertCollection('name')
C. db.newCollection('name')
D. db.createCollection('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.delete()
D. db.users.drop()

11 Which command deletes the currently selected database?

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

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

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

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

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

14 Which method retrieves all documents from a collection?

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

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

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

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

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

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

A. $change
B. $modify
C. $update
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. updateMany is deprecated.
D. They function identically.

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. 27017
B. 8080
C. 5432
D. 3306

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

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

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

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

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

A. node install mongoose
B. npm add mongoose-db
C. npm install mongo
D. npm 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 query builder.
D. A configuration object defining the structure and rules of data.

25 Which function is used to create a Mongoose Schema?

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

26 What is a Mongoose 'Model'?

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

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

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

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

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

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

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

30 Which Mongoose method finds a document by its _id?

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

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.connect(connectionString)
B. mongoose.open(connectionString)
C. mongoose.start(connectionString)
D. mongoose.db.connect(connectionString)

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

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

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

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

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. updateById
B. findAndModify
C. saveById
D. findByIdAndUpdate

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. Returns the first document where age is 25.
B. Updates documents where age is 25.
C. Returns all documents 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. Table
D. Array

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

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

41 In Node.js, most MongoDB operations are:

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

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

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

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

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

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 rigid schemas; NoSQL has dynamic/flexible schemas.
B. SQL has dynamic schemas; NoSQL has rigid 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 error
B. undefined
C. null
D. An empty array []

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

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

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: -1 })
C. .sort({ field: 'desc' })
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: { type: Array, contains: String }
C. tags: String[]
D. tags: Array<String>