Home Interview Questions and Answers MongoDB Interview Questions and Answers For Freshers Part-2

mongodb11.How can you achieve primary key – foreign key relationships in MongoDB?
By default MongoDB does not support such primary key – foreign key relationships. However, we can achieve this concept by embedding one document inside another. Foe e.g. an address document can be embedded inside customer document.

12.Does MongoDB need a lot of RAM?
No. MongoDB can be run even on a small amount of RAM. MongoDB dynamically allocates and de-allocates RAM based on the requirements of other processes.

13.Does MongoDB pushes the writes to disk immediately or lazily?
MongoDB pushes the data to disk lazily. It updates the immediately written to the journal but writing the data from journal to disk happens lazily.

14.Explain the structure of ObjectID in MongoDB.
ObjectID is a 12-byte BSON type with:

4 bytes value representing seconds
3 byte machine identifier
2 byte process id
3 byte counter

15.MongoDB uses BSON to represent document structures. True or False?

16.If you remove a document from database, does MongoDB remove it from disk?
Yes. Removing a document from database removes it from disk too.

17.Mention the command to insert a document in a database called school and collection called persons.
db.products.insert( { item: “card”, qty: 15 } )

18.What are Indexes in MongoDB?
Indexes support the efficient execution of queries in MongoDB. Without indexes, MongoDB must perform a collection scan, i.e. scan every document in a collection, to select those documents that match the query statement. If an appropriate index exists for a query, MongoDB can use the index to limit the number of documents it must inspect.

19.How many indexes does MongoDB create by default for a new collection?
By default, MongoDB created the _id collection for every collection.

20.Can you create an index on an array field in MongoDB? If yes, what happens in this case?
Yes. An array field can be indexed in MongoDB. In this case, MongoDB would index each value of the array.

You may also like

Leave a Comment