MongoDB Interview Questions and Answers

What are the indexes in MongoDB?

In MongoDB , indexes are special structures, which stores a small portion of the data set in an easy to traverse form. The sequence of the value of the field are specified in the index. An index stores the value of an individual field or set of fields.

What is the basic syntax to use index?

The basic syntax to use in MongoDB is >db.COLLECTION_NAME.ensureindex ( {KEY:1} ). In this key is the name of the on which you want to make an index, where 1 is for accessing sequence otherwise you use -1 for descending order.

Mention what is alternative to MongoDB?   

An alternative to MongoDB is Cassandra, HBase, Redis, CouchDB.

Explain what is the method to configure the cache size in MongoDB?

MongoDB’s cache is not configurable. So, MongoDB uses all the free spaces on the system automatically by way of memory mapped files.

Mention how do you use indexes in a collection?

To list a collection’s index, use the db.collection.getIndexes() method otherwise a similar method based on your driver.

Mention how you consider the size of an index?

To determine the size of the indexes on a collection, use db.collcetion.stats().

Explain what happens if an index does not fit into RAM?

In this case when an index is too big size fit into RAM, then MongoDB read the index from disk, which provide slower operation than reading from RAM. If keep in mind an index fits into RAM when your server has RAM present for the index combined with the rest of the working set.

Mention how does MongoDB provide concurrency?

MongoDB uses writer and reader locks that give concurrent readers shared access to a resource, like a database or collection, but provide exclusive access to a single write operation.