General Flashcards

1
Q

What is MongoDB?

A

MongoDB is a NoSQL database program that uses JSON-like documents with optional schemas.

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

What is a NoSQL database?

A

A NoSQL database provides a mechanism for storage and retrieval of data that is modeled in means other than the tabular relations used in relational databases.

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

How does MongoDB store data?

A

MongoDB stores data in flexible, JSON-like documents, meaning fields can vary from document to document and data structure can be changed over time.

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

What is a collection in MongoDB?

A

A collection is a group of MongoDB documents. It is the equivalent of an RDBMS table, but it doesn’t enforce any structure.

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

What is a document in MongoDB?

A

A document is a record in a MongoDB collection, similar to a row in a table of an RDBMS.

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

What is the purpose of BSON in MongoDB?

A

BSON (Binary JSON) is a binary-encoded serialization of JSON-like documents. It supports more data types than JSON.

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

How does MongoDB handle indexing?

A

MongoDB supports various types of indexes including single field, compound, multikey, geospatial, text, hashed, clustered (>= v5.3) indexes.

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

What is sharding in MongoDB?

A

Sharding is the process of storing data records across multiple machines to ensure horizontal scalability.

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

What is replication in MongoDB?

A

Replication is the process of synchronizing data across multiple servers to provide redundancy and high availability.

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

What is a replica set in MongoDB?

A

A replica set is a group of MongoDB instances that maintain the same data set, providing redundancy and high availability.

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

What are the advantages of using MongoDB over relational databases?

A

Advantages include a flexible schema design, easier scalability, high performance for certain types of workloads, and simpler management of large datasets.

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

What are the disadvantages of MongoDB?

A

Disadvantages include the potential for increased complexity in certain scenarios, less mature tooling compared to relational databases, and specific use cases where relational databases might be more efficient.

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

What is the Aggregation Framework in MongoDB?

A

The Aggregation Framework is a set of operations that process data records and return computed results. It provides a way to transform and combine data.

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

What is a primary key in MongoDB?

A

In MongoDB, the primary key is automatically set to the _id field in each document. Each document’s _id must be unique within a collection.

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

How does MongoDB ensure ACID transactions?

A

MongoDB ensures ACID transactions at the document level and, starting with version 4.0, it supports multi-document transactions to provide atomicity, consistency, isolation, and durability across multiple documents.

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

What are some common use cases for MongoDB?

A

Common use cases include content management, real-time analytics, Internet of Things (IoT) applications, mobile applications, and catalog management.

17
Q

What is the difference between MongoDB and MySQL?

A

MongoDB is a NoSQL, document-oriented database, while MySQL is a relational database management system (RDBMS). MongoDB uses JSON-like documents, whereas MySQL uses structured tables and rows.

18
Q

What is the role of the _id field in MongoDB?

A

The _id field in MongoDB serves as the primary key for a document in a collection. It uniquely identifies each document and is required in every document.

19
Q

How can you create a new database in MongoDB?

A

In MongoDB, a new database is created when you first store data in that database. You can switch to a new database using the use command, followed by the name of the database.

20
Q

What is a capped collection in MongoDB?

A

A capped collection is a fixed-size collection that maintains insertion order and, once the specified size limit is reached, overwrites the oldest documents.

21
Q

What is GridFS in MongoDB?

A

GridFS is a specification for storing and retrieving large files, such as images, videos, and documents, in MongoDB. It splits files into smaller chunks and stores each chunk as a separate document.

22
Q

How does MongoDB handle concurrency?

A

MongoDB uses a combination of multi-granularity locking, including reader-writer locks at the database, collection, and document levels, to manage concurrency.

23
Q

What is a MongoDB query language (MQL)?

A

MongoDB Query Language (MQL) is the language used to interact with MongoDB, allowing users to perform CRUD operations, query documents, and interact with the database.

24
Q

How do you update a document in MongoDB?

A

To update a document in MongoDB, you use the updateOne, updateMany, or replaceOne methods, specifying the criteria for the document(s) to update and the new values.

25
Q

What is a projection in MongoDB?

A

A projection in MongoDB is used to specify which fields to include or exclude in the returned documents when querying a collection.

26
Q

How can you delete documents in MongoDB?

A

You can delete documents in MongoDB using the deleteOne or deleteMany methods, specifying the criteria for the document(s) to delete.

27
Q

What is the purpose of the explain method in MongoDB?

A

The explain method provides detailed information about how MongoDB executes a query, including the query plan and performance statistics.

28
Q

What are some security features of MongoDB?

A

Security features of MongoDB include authentication, authorization, encryption, auditing, and IP whitelisting.

29
Q

What is the use of the $lookup operator in MongoDB?

A

The $lookup operator is used to perform left outer joins with other collections, allowing you to combine data from multiple collections in a single query.

30
Q

How do you back up a MongoDB database?

A

To back up a MongoDB database, you can use tools like mongodump to create binary dumps of the database, or perform file system snapshots, or use MongoDB Atlas’s built-in backup capabilities.

31
Q

What is a change stream in MongoDB?

A

A change stream allows applications to access real-time data changes in a collection, database, or deployment without polling the database.

32
Q

How can you ensure data consistency in MongoDB?

A

Data consistency in MongoDB is ensured through the use of replica sets, write concern settings, and transactions.

33
Q

What is the difference between find() and findOne() in MongoDB?

A

The find() method returns a cursor to all documents that match the query criteria, while the findOne() method returns only the first document that matches the query criteria.

34
Q

How does MongoDB handle schema changes?

A

MongoDB’s flexible schema allows for changes at the document level without affecting the entire database. Fields can be added or removed from documents as needed.

35
Q

What is the purpose of the $match stage in an aggregation pipeline?

A

The $match stage filters documents in an aggregation pipeline to pass only those documents that match the specified conditions to the next stage.

36
Q

How do you create an index in MongoDB?

A

To create an index in MongoDB, you use the createIndex method on a collection, specifying the fields to be indexed and the index type.