MongoDB Interview Questions and Answers

Explain how replication works in MongoDB?

Across more servers the process of synchronizing data is called replication. Replication gives redundancy and growing data availability with more copies of data on different database servers. It Provide in protecting the database from the loss of a single server.

How to create Schema in MongoDB and what are the points to be considered?

There are following points need to be taken into consideration are:

  • Creating your schema according to client requirements
  • Adding objects into one document if you use them together. Or separate them
  • Do joins while to write, and not when it is to read
  • For most easily use cases optimize your schema
  • Do complex aggregation in the Schema

Explain what is the syntax to create a collection and to drop a collection in MongoDB?

  • The syntax for creating collection in the MongoDB is db.createCollection(name, options)
  • The syntax for drop collection in the MongoDB is db.collection.drop()

Mention how you can  move the old file in the moveChunk directory?

Yes, of course, to move the old file in the moveChunk directory at the time of shard balancing operations these files are made as backups and can be removed once the operation are done.

To do Safe backups what features are used in MongoDB?

The journaling is the feature in MongoDB that you can use to do safe backups.

What is the Object ID composed of in MongoDB?

Object ID is composed of:

  • 3 bytes incremented counter
  • Client machine ID
  • Timestamp
  • Client process ID

What is the command syntax for inserting a document in MongoDB?

In MongoDB inserting a document command syntax is database.collcetion.insert(document).