MongoDB Interview Questions and Answers For Freshers Part-4
31.What are Primary and Secondary Replica sets?
Primary and master nodes are the nodes that can accept writes. MongoDB’s replication is ‘single-master:’ only one node can accept write operations at a time.
Secondary and slave nodes are read-only nodes that replicate from the primary.
32.By default, MongoDB writes and reads data from both primary and secondary replica sets. True or False.
False. MongoDB writes data only to the primary replica set.
33.Why are MongoDB data files large in size?
MongoDB preallocates data files to reserve space and avoid file system fragmentation when you setup the server.
34.When should we embed one document within another in MongoDB?
You should consider embedding documents for:
‘contains’ relationships between entities
35.Why MongoDB is not preferred over a 32-bit system?
When running a 32-bit build of MongoDB, the total storage size for the server, including data and indexes, is 2 gigabytes. For this reason, do not deploy MongoDB to production on 32-bit machines.
If you’re running a 64-bit build of MongoDB, there’s virtually no limit to storage size.
36.What is a Storage Engine in MongoDB
A storage engine is the part of a database that is responsible for managing how data is stored on disk. For example, one storage engine might offer better performance for read-heavy workloads, and another might support a higher-throughput for write operations.
37.Which are the two storage engines used by MongoDB?
MongoDB uses MMAPv1 and WiredTiger.
38.What is the role of a profiler in MongoDB? Where does the writes all the data?
The database profiler collects fine grained data about MongoDB write operations, cursors, database commands on a running mongod instance. You can enable profiling on a per-database or per-instance basis.
The database profiler writes all the data it collects to the system.profile collection, which is a capped collection.
39.How does Journaling work in MongoDB?
When running with journaling, MongoDB stores and applies write operations in memory and in the on-disk journal before the changes are present in the data files on disk. Writes to the journal are atomic, ensuring the consistency of the on-disk journal files. With journaling enabled, MongoDB creates a journal subdirectory within the directory defined by dbPath, which is /data/db by default.
40.Mention the command to check whether you are on the master server or not.