General Flashcards

1
Q

What is a replica set and what is its purpose?

A

A replica set is a MongoDB cluster that stores the same data in more than one server and its purpose is to provide redundancy and availability in the event of a server failure

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a MongoDB cluster?

A

A MongoDB cluster is a group of MongoDB servers working as a unit

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is MongoDB Atlas and what is its purpose?

A

MongoDB Atlas is a multi-cloud database platform and its purpose is to simplify deploying and managing databases

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How is MongoDB different than MySQL?

A
  • MongoDB is flexible while MySQL is strict
  • MongoDB uses collections and BSON documents while MySQL uses tables of rows and columns
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a document?

A

A document is a record. It is the basic unit of data in MongoDB

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a collection?

A

A collection is a group of documents

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a database?

A

A database is a group of collections

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is MongoDB?

A

MongoDB is a general purpose document database

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

True or False

Documents in the same collection must have the same field structure and data types

A

False. Documents in the same collection can have different field structures and data types

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the difference between BSON and JSON?

A

BSON is an extension of JSON. BSON supports more data types than JSON

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is BSON?
What is its maximum size?

A

BSON is a binary-encoded JSON object. It’s maximum size is 16 MB

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

True or False

MongoDB documents are displayed in JSON and stored as BSON

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

True or False

Documents do not require an _id field

A

False. All documents require an _id field. In fact, if a document is inserted without an _id field, MongoDB will automatically create an ObjectId instance for that field

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the definition of “schema”

A

Schema is equivalent to “data model”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What feature can be used to put constraints on a flexible schema?

A

MongoDB schema validation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the purpose of a connection string?

A

The purpose of a connection string is to provide all of the necessary instructions for a client to connect to MongoDB

17
Q

What is MongoDB Compass and what is its purpose?

A

MongoDB Compass is a GUI used to query and analyze a MongoDB cluster

18
Q

What is a MongoDB driver and what is it used for?

A

A MongoDB driver is a language-specific library used to interact with MongoDB

19
Q

True or False

A MongoClient should be created for every query

A

False. That is an extremely inefficient way of interacting with a database. Only a single MongoClient instance should be created per application

20
Q

What is the difference between replaceOne() and updateOne()?

A

replaceOne() will override the current document’s fields with the ones specified. This means, if the original document had 5 fields but the replacing document only has 1, the new document will only have 1 field. updateOne() only updates the fields specified by the updating document and does not affect other fields

21
Q

When are databases and collections first created?

A

Databases and collections are first created when a document is inserted

22
Q

What types can be used as the _id field?

A

Any type other than arrays or null

23
Q

Is the _id field mutable or immutable?

A

Immutable

24
Q

What is the purpose of collation?

A

The purpose of collation is to specify language-specific rules for string comparisons

25
Q

List the 13 most common BSON data types and their respective bits if applicable

A
  1. byte 8-bits
  2. int 32-bits
  3. long 64-bits
  4. double 64-bits
  5. decimal 128-bits
  6. boolean
  7. null
  8. Array
  9. Object
  10. String 8-bits
  11. Date
  12. Timestamp
  13. ObjectId
26
Q

What are the 2 ways to close a cursor?

A

By closing the cursor explicitly or by exhausting the elements in the cursor

27
Q

What is the purpose of db.getSiblingDB("...")?

A

The purpose of getSiblingDB() is to be able to reference another database without having to change db in mongosh

28
Q

What is a blocking sort and when does it normally occur?

A

A blocking sort is a sort executed in memory. This normally occurs when an indexed sort cannot be performed

29
Q

What is the purpose of a connection pool?

A

The purpose of a connection pool is to prevent the need of having to open a new connection for every database operation

30
Q

What is the easiest way to change the connection pool size?

A

By specifying a query parameter on the connection string. For example:

mongodb+srv://.../?maxPoolSize=10
31
Q

What is the difference between countDocuments() and estimatedDocumentCount()?

A

countDocuments() iterates through the entire collection to count the total number of documents (slower but 100% precise). estimatedDocumentCount() does not iterate the collection and obtains the total number of documents from metadata (faster but not 100% precise)

32
Q

What is the default connection pool size in the Java driver?

A

100

33
Q

True or False

Unlike JSON objects, the fields in a BSON document are ordered

A

True. This is important to keep in mind when querying for exact document matches

34
Q

When querying for exact document matching, what should you always keep in mind?

A

When querying for exact document matching, remeber that BSON documents are ordered. It is extremely important that the order of the fields you are using in your query are in the same order as the fields in the document you are trying to retrieve

35
Q

Review

Specifies the number of documents to return in each batch of the response from the MongoDB instance. In most cases, modifying the batch size will not affect the user or the application, as mongosh and most drivers return results as if MongoDB returned a single batch.

36
Q

Review

find() and aggregate() operations have an initial batch size of 101 documents by default. Subsequent getMore operations issued against the resulting cursor have no default batch size, so they are limited only by the 16 megabyte message size.