January 27, 2020

#MongoDB Part 4: Interview Questions And Answers

What is Namespace in MongoDB?
MongoDB stores BSON (Binary Interchange and Structure Object Notation) objects in the collection. The concatenation of the collection name and database name is called a namespace.

What is sharding in MongoDB?
Sharding is the procedure of storing data records across multiple machines. It is a MongoDB approach to meet the demands of data growth. Sharding is the horizontal partition of data in a database or search engine. Each partition is referred as shard or database shard.

Can you move old files in the moveChunk directory?
Yes we can move them during normal shard balancing operations these files are made as backups and can be deleted once the operations are done.

To do safe backups what is the feature in MongoDB that you can use?
Journaling is the feature in MongoDB that we can use to do safe backups.

How can you see the connection used by Mongos?
use db_adminCommand ("connPoolStats");

While creating Schema in MongoDB what are the points need to be taken in consideration?
  • Design the schema according to user requirements
  • Combine objects into one document if you use them together. Otherwise, separate them.
  • Do joins while write, and not when it is on read
  • For most frequent use cases optimize your schema
  • Do complex aggregation in the schema.
What is the syntax to create a collection and to drop a collection in MongoDB?
db.createCollection(name,options);
db.collection.drop();

What is the role of profiler in MongoDB?
MongoDB database profiler shows performance characteristics of each operation against the database. We can find queries using the profiler that are slower than they should be. Profiler stores all the data in system.profile collection

Objectld composed of?
ObjectId is a class which is the default primary key for the document in MongoDB. It is found in the _id field of the inserted document. It is a 12-byte BSON type generated using a default algorithm and is composed of:
  • Timestamp: 4-byte value that represents seconds since Unix epoch
  • Client machine ID: 3-byte machine id
  • Client process ID: 2-byte process id
  • Incremented counter: 3-bytes counter that starts with a random number
What is the command syntax for inserting a document?
database.collection.insert(document).

How you can inspect the source code of a function?
To inspect a source code of a function, without any parentheses, the function must be invoked.

What is the command syntax that tells you whether you are on the master server or not? And how many master does MongoDB allow?
Db.isMaster() will tell us whether we are on the master server or not. MongoDB allows only one master server, while couchDB allows multiple masters.

What is the command syntax that is used to view Mongo is using the link?
db._adminCommand("connPoolStats.")

What are indexes in MongoDB?
Indexes are special structures in MongoDB, which stores a small portion of the data set in an easy to traverse form. Ordered by the value of the field specified in the index, the index stores the value of a specific field or set of fields.

What is the basic syntax to use index in MongoDB?
db.COLLECTION_NAME.ensureIndex ( {KEY:1} ). Where the key is the the name of the COLUMN which is present in the documents.

-K Himaanshu Shuklaa..

No comments:

Post a Comment