Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

What If A Shard Is Down Or Slow And I Do A Query?

Answer»

If a SHARD is down, the QUERY will RETURN an error unless the "Partial" query OPTIONS is set. If a shard is responding slowly, mongos will wait for it.

If a shard is down, the query will return an error unless the "Partial" query options is set. If a shard is responding slowly, mongos will wait for it.

2.

What Happens If I Try To Update A Document On A Chunk That Is Being Migrated?

Answer»

The update will GO through immediately on the OLD SHARD, and then the CHANGE will be replicated to the NEW shard before ownership transfers.

The update will go through immediately on the old shard, and then the change will be replicated to the new shard before ownership transfers.

3.

How Does Sharding Work With Replication?

Answer»

Each SHARD is a logical collection of PARTITIONED data. The shard could consist of a single SERVER or a cluster of replicas. We recommend USING a replica set for each shard.

Each shard is a logical collection of partitioned data. The shard could consist of a single server or a cluster of replicas. We recommend using a replica set for each shard.

4.

Should I Start Out With Sharded Or With A Non-sharded Mongodb Environment?

Answer»

We suggest STARTING unsharded for SIMPLICITY and quick startup unless your initial data set will not fit on single SERVERS.

Upgrading to sharding from unsharded is easy and seamless, so there is not a lot of advantage to setting up sharding before your data set is LARGE.

We suggest starting unsharded for simplicity and quick startup unless your initial data set will not fit on single servers.

Upgrading to sharding from unsharded is easy and seamless, so there is not a lot of advantage to setting up sharding before your data set is large.

5.

What's A Secondary Or Slave?

Answer»

A secondary is a node/member which applies operations from the current primary. This is done by tailing the REPLICATION oplog (local.oplog.rs).

Replication from primary to secondary is asynchronous, HOWEVER the secondary will TRY to stay as CLOSE to current as possible (often this is just a few milliseconds on a LAN).

A secondary is a node/member which applies operations from the current primary. This is done by tailing the replication oplog (local.oplog.rs).

Replication from primary to secondary is asynchronous, however the secondary will try to stay as close to current as possible (often this is just a few milliseconds on a LAN).

6.

What's A Master Or Primary?

Answer»

This is a node/member which is currently the primary and PROCESSES all WRITES for the REPLICA set. In a replica set, on a failover event, a different member can BECOME primary.

This is a node/member which is currently the primary and processes all writes for the replica set. In a replica set, on a failover event, a different member can become primary.

7.

How Long Does Replica Set Failover Take?

Answer»

It may take 10-30 seconds for the PRIMARY to be declared down by the other MEMBERS and a new primary elected.

During this window of time, the cluster is down for "primary" operations – that is, writes and STRONG consistent reads. However, you may execute EVENTUALLY consistent queries to secondaries at any time (in slaveOk mode), INCLUDING during this window.

It may take 10-30 seconds for the primary to be declared down by the other members and a new primary elected.

During this window of time, the cluster is down for "primary" operations – that is, writes and strong consistent reads. However, you may execute eventually consistent queries to secondaries at any time (in slaveOk mode), including during this window.

8.

Why Are My Data Files So Large?

Answer»

MongoDB does aggressive PREALLOCATION of RESERVED space to avoid FILE system FRAGMENTATION.

MongoDB does aggressive preallocation of reserved space to avoid file system fragmentation.

9.

How Do I Do Transactions/locking?

Answer»

MongoDB does not use traditional LOCKING or complex transactions with rollback, as it is designed to be lightweight and fast and predictable in its performance.

It can be thought of as analogous to the MySQL MyISAM autocommit model. By keeping TRANSACTION support EXTREMELY simple, performance is enhanced, especially in a system that MAY run ACROSS many servers.

MongoDB does not use traditional locking or complex transactions with rollback, as it is designed to be lightweight and fast and predictable in its performance.

It can be thought of as analogous to the MySQL MyISAM autocommit model. By keeping transaction support extremely simple, performance is enhanced, especially in a system that may run across many servers.

10.

Does An Update Fsync To Disk Immediately?

Answer»

No, writes to disk are lazy by default. A write may hit disk a couple of seconds later.

For example: if the DATABASE receives a thousand increments to an object within one second, it will only be flushed to disk once. (Note rsync OPTIONS are AVAILABLE though both at the command line and VIA getLastError OLD.)

No, writes to disk are lazy by default. A write may hit disk a couple of seconds later.

For example: if the database receives a thousand increments to an object within one second, it will only be flushed to disk once. (Note rsync options are available though both at the command line and via getLastError old.)

11.

Are Null Values Allowed?

Answer»

For MEMBERS of an object, YES. You cannot add null to a DATABASE COLLECTION though as null is not an object. You can add {}, though.

For members of an object, yes. You cannot add null to a database collection though as null is not an object. You can add {}, though.

12.

Can I Use The Journaling Feature To Perform Safe Hot Backups?

Answer»

Yes

Yes

13.

If You Remove An Object Attribute Is It Deleted From The Store?

Answer»

YES, you REMOVE the ATTRIBUTE and then re-save() the OBJECT.

Yes, you remove the attribute and then re-save() the object.

14.

What Is Role Of Profiler In Mongodb?

Answer»

MONGODB includes a database profiler which shows performance characteristics of each operation against the database. Using the profiler you can find QUERIES (and write OPERATIONS) which are SLOWER than they should be; USE this information, for example, to determine when an index is needed.

MongoDB includes a database profiler which shows performance characteristics of each operation against the database. Using the profiler you can find queries (and write operations) which are slower than they should be; use this information, for example, to determine when an index is needed.

15.

Will The Journal Replay Have Problems If Entries Are Incomplete (like The Failure Happened In The Middle Of One)?

Answer»

Each journal (group) WRITE is CONSISTENT and won't be replayed during RECOVERY unless it is complete.

Each journal (group) write is consistent and won't be replayed during recovery unless it is complete.

16.

What Is 32 Bit Nuances?

Answer»

There is extra memory MAPPED file activity with journaling. This will further CONSTRAIN the limited db size of 32 BIT builds. Thus, for now journaling by default is DISABLED on 32 bit systems.

There is extra memory mapped file activity with journaling. This will further constrain the limited db size of 32 bit builds. Thus, for now journaling by default is disabled on 32 bit systems.

17.

What Makes Mongodb Best?

Answer»

Following features of MongoDB make it BEST NoSQL database:

  1. Document-oriented
  2. HIGH performance
  3. High availability
  4. EAZY scalability
  5. Rich query LANGUAGE

Following features of MongoDB make it best NoSQL database:

18.

How Do You Compare Mongodb With Couchdb And Couchbase?

Answer»
  • MONGODB and CouchDB are both document-oriented databases. MongoDB and CouchDB are the best examples of open source NoSQL DATABASE.
  • Aside from both storing documents though, it turns out that they don't share much in common.
  • There are a lot of DIFFERENCE between MongoDB and CouchDB in terms of implementation of their data-model, interface, object storage, REPLICATION METHODS etc.

19.

What Is The Basic Difference Between Mysql And Mongodb?

Answer»

MySQL and MongoDB are both free and open SOURCE databases.

MySQL and MongoDB have a lot of basic DIFFERENCES in terms of data representation, querying, RELATIONSHIPS, transactions, SCHEMA design and definition, normalization, speed and performance.

By comparing MySQL with MongoDB, we are comparing Relational and non-relational databases.

MySQL and MongoDB are both free and open source databases.

MySQL and MongoDB have a lot of basic differences in terms of data representation, querying, relationships, transactions, schema design and definition, normalization, speed and performance.

By comparing MySQL with MongoDB, we are comparing Relational and non-relational databases.