MongoDB Interview Questions

  1. What is MongoDB?
    • MongoDB, classified as a NoSQL database, is a document based database which provides high performance, high availability and easy scalability.
  2. Compare traditional relational databases like SQL to MongoDB.
    • Relational databases are powerful and flexible but constrained; they were designed with database administrators in mind.
    • NoSql databases were designed with programmers in mind, where the document model more closely match code objects.
  3. While creating a Schema in MongoDB what are the points that need to be taken in consideration?
    • Points that need to be taken in consideration are
      • Design your 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
  4. What is indexing?
    • 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.
  5. Describe some features of indexing supported by MongoDB.
    • MongoDB allows for up to 64 indices per collection
    • The single field index makes it faster to access and query that specific field. Helpful for when a specific field is going to be queried very often.
    • The compound index is a single index that uses multiple fields to create a lookup table to make a wide range of queries.
    • MongoDB also allows for uniqueness rules via indexing; can create this index before creating objects to force these rules onto objects.
  6. What is sharding?
    • Sharding is a procedure where data records are stored across multiple machines. It provides scalability via software rather than an expensive solution that would be needed in relational databases like SQL. Sharding is the horizontal partition of data in a database or search engine. Each partition is referred to as a shard or database shard. It can be challenging to set up Sharding, but it makes it possible to manage large databases without paying for larger systems for the data size to expand.
  7. What is replication?
    • Replication is a process of synchronizing data across multiple servers, ensuring reliability and availibility of the data. With replication, you keep multiple copies of data on different database servers. It protects the database from going down based on a single server going down with the use of replica sets.
  8. What is a replica set?
    • A replica set is a group of instances that host the same data set. In the replica set one node is primary and another is secondary. From primary to the secondary node, all data replicates.
      • If your primary server goes down, another server will automatically be promoted to be the new main server. When the original primary server comes back up, it will take its place as a secondary server.
  9. What is aggregation?
    • Aggregations are operations that process data records and return computed results.
  10. Compare Update and Set queries.
    • Update replace entire object and set only the values specified in the query. It completely overwrites the original.
    • Set is generally used more often than Update because it supports a partial update and not leave unspefied values empty, instead using the original values of the object for them.
  11. What are some advantages of embedded data structure?
    • MongoDB supports nested arrays and objects rather than simply keys and values. It supports operation at any depth of nesting even up to 100 levels. Embedded data in MongoDB can be easier to work with, minimizes coding operations and is easier to query and index. One downside is that it won’t update values automatically across documents.
  12. What are some advantages of the include by references structure?
    • References allow you to address each collection separately. It can protect you from having to update the same data in multiple places therefore enabling consistent data.
  13. What is the ObjectId–what is it made of?
    • ObjectId is the default primary key for a MongoDB document
      • Objectld is composed of
        • Timestamp
        • Client machine ID
        • Client process ID
        • 3 byte incremented counter
  14. How does MongoDB store objects in the collection?
    • MongoDB stores BSON (Binary Interchange and Structure Object Notation) objects in the collection.
  15. What is the syntax to create a collection and to drop a collection in MongoDB?
    • Syntax to create collection in MongoDB is db.createCollection(name,options)
    • Syntax to drop collection in MongoDB is db.collection.drop()

Sources:

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.