1. What do you understand by NoSQL databases? Is MongoDB a NoSQL database? explain.  

Short Answer

NoSQL is a class of database management systems (DBMS) that do not follow all of the rules of a relational DBMS and cannot use traditional SQL to query data.
Yes. MongoDB is a NoSQL database.

Long Answer

At the present time, the internet is loaded with big data, big users, big complexity etc. and also becoming more complex day by day. NoSQL is answer of all these problems, It is not a traditional database management system, not even a relational database management system (RDBMS). NoSQL stands for "Not Only SQL". NoSQL is a type of database that can handle and sort all type of unstructured, messy and complicated data. It is just a new way to think about the database.

Yes. MongoDB is a NoSQL database.

2. What are the different types of NoSQL databases? Give some example.  

NoSQL database can be classified as 4 basic types:

  • Key value store NoSQL database
  • Document store NoSQL database
  • Column store NoSQL database
  • Graph base NoSQL databse

There are many NoSQL databases. MongoDB, Cassandra, CouchBD, Hypertable, Redis, Riak, Neo4j, HBASE, Couchbase, MemcacheDB, Voldemort, RevenDB etc. are the examples of NoSQL databases.

3. What type of DBMS is MongoDB?  

MongoDB is a document oriented DBMS.

4. What is the difference between MongoDB and MySQL?  

Short Answer

Although MongoDB and MySQL both are free and open source databases, there is a lot of difference between them in the term of data representation, relationship, transaction, querying data, schema design and definition, performance speed, normalization and many more. To compare MySQL with MongoDB is like a comparison between Relational and Non-relational databases.

Long Answer

1. There is a difference in the representation of data in the two databases. In MongoDB, data represents in a collection of JSON documents while in MySQL, data is in tables and rows. JSON documents can compare to associative arrays when using PHP and directory objects when using Python.

2. When it comes to querying, you have to put a string in the query language that the DB system parses. The query language is called Structured Query Language, or SQL,from where MySQL gets its name. This exposes your DB susceptible to SQL injectionattacks. On the other hand, MongoDB’s querying is object-oriented, which means you pass MongoDB a document explaining what you are querying. There is no parsing whatsoever, which will take some time getting used to if you already use SQL.

3. One of the greatest benefits of relational databases like MySQL is the JOIN operation. The operation allows for the querying across several tables. Although MongoDB doesn’t support joints, it supports multi-dimensional data types like other documents and arrays.

4. With MySQL, you can have one document inside another (embedding). You would have to create one table for comments and another for posts if you are using MySQL to create a blog. In MongoDB, you will only have one array of comments and one collection of posts within a post.

5. MySQL supports atomic transactions. You can have several operations within a transaction and you can roll back as if you have a single operation. There is no support for transactions in MongoDB and the single operation is atomic.

6. One of the best things about MongoDB is that you are not responsible for defining the schema. All you need to do is drop in documents. Any 2 documents in a collection need not be in the same field. You have to define the tables and columns before storage in MySQL. All rows in a table share the same columns.

7. MongoDB’s performance is better than that of MySQL and other relational DBs. This is because MongoDB sacrifices JOINS and other things and has excellent performance analysis tools. Note that you still have to index the data and the data in most applications is not enough for them to see a difference. MySQL is criticized for poor performance, especially in ORM application. However, you are unlikely to have an issue if you do proper data indexing and you are using a database wrapper.

8. One advantage of MySQL over NoSQL like MongoDB is that the community in MySQL is much better than NoSQL. This is mostly because NoSQL is relatively new while MySQL has been around for several years.

9. There are no reporting tools with MongoDB, meaning performance testing and analysis is not always possible. With MySQL, you can get several reporting tools that help you rove the validity of your applications.

10. RDBSs function on a paradigm called ACID, which is an acronym for (Atomicity, Consistency, Isolation, and Durability). This is not present in MongoDB database.

11. MongoDB has a Map Reduce feature that allows for easier scalability. This means you can get the full functionality of MongoDB database even if you are using low-cost hardware.

12. You do not have to come up with a detailed DB model with MongoDB because of is non-relational. A DB architect can quickly create a DB without a fine-grained DB model, thereby saving on development time and cost.

5. Why MongoDB is known as best NoSQL database?  

MongoDb is the best NoSQL database because, it is:

  • Document Oriented
  • Rich Query language
  • High Performance
  • Highly Available
  • Easily Scalable

6. What is the difference b/w MongoDB and CouchDB?  

Short Answer

MongoDB and CouchDB both are the great example of open source NoSQL database. both are document oriented databases. Although both stores data but there is a lot of difference between them in terms of implementation of their data models, interfaces, object storage and replication methods etc.

Long Answer

CouchDB is written in Erlang, a computer language highly optimized for concurrency, distribution and fault tolerance. Beside being fast from the name and logo we can have a hint that the database was targeted for easy use. Their focus was to increase developers's productivity by having easy to use tools.

A document is a JSON object, very easy to integrate with web applications where JSON is the most used format. A flat collection of these documents is a couchdb database and each document is identified by a key ID. Each document has also a revision number (_rev) for each change in the document.

CouchDB has some advantages over MongoDB with features like:
- multi master replication which is very helpful when two databases are located in two different datancenters;
- built-in HTTP REST API;
- no database locking, thanks to MVCC.

In the same time some great features from MongoDB are not supported in CouchDB:
- auto sharding which make very easy to scale write operations;
- automatic failover of nodes.
- built-in full text search
- monitoring service like MMS

7. What is a Namespace in MongoDB?  

Namespace is a concatenation of the database name and the collection name. Collection, in which MongoDB stores BSON objects.

8. Why does Profiler use in MongoDB?  

MongoDB uses a database profiler to perform characteristics of each operation against the database. You can use a profiler to find queries and write operations

9. If you remove an object attribute, is it deleted from the database?  

Yes, it be. Remove the attribute and then re-save() the object.

10. In which language MongoDB is written?  

MongoDB is written and implemented in C++.

11. Does MongoDB need a lot space of Random Access Memory (RAM)?  

No. MongoDB can be run on small free space of RAM.

12. What language you can use with MongoDB?  

MongoDB client drivers supports all the popular programming languages so there is no issue of language, you can use any language that you want.

13. Does MongoDB database have tables for storing records?  

No. Instead of tables, MongoDB uses "Collections" to store data.

14. Do the MongoDB databases have schema?  

Yes. MongoDB databases have dynamic schema. There is no need to define the structure to create collections.

15. What is the method to configure the cache size in MongoDB?  

MongoDB's cache is not configurable. Actually MongoDb uses all the free spaces on the system automatically by way of memory mapped files.

16. How to do Transaction/locking in MongoDB?  

MongoDB doesn't use traditional locking or complex transaction with Rollback. MongoDB is designed to be light weighted, fast and predictable to its performance. It keeps transaction support simple to enhance performance.

17. Why 32 bit version of MongoDB are not preferred ?  

Short Answer

Because MongoDB uses memory mapped files so when you run a 32-bit build of MongoDB, the total storage size of server is 2 GB. But when you run a 64-bit build of MongoDB, this provides virtually unlimited storage size. So 64-bit is preferred over 32-bit.

Long Answer

32-bit MongoDB processes are limited to about 2 gb of data. This has come as a surprise to a lot of people who are used to not having to worry about that. The reason for this is that the MongoDB storage engine uses memory-mapped files for performance.

By not supporting more than 2gb on 32-bit, we’ve been able to keep our code much simpler and cleaner. This greatly reduces the number of bugs, and reduces the time that we need to release a 1.0 product. The world is moving toward all 64-bit very quickly. Right now there aren’t too many people for whom 64-bit is a problem, and in the long term, we think this will be a non-issue.

18. Is it possible to remove old files in the moveChunk directory?  

Yes, These files can be deleted once the operations are done because these files are made as backups during normal shard balancing operation. This is a manual cleanup process and necessary to free up space.

19. What will have to do if a shard is down or slow and you do a query?  

If a shard is down and you even do query then your query will be returned with an error unless you set a partial query option. But if a shard is slow them Mongos will wait for them till response.

20. What are alternatives to MongoDB?  

Cassandra, CouchDB, Redis, Riak, HBase are a few good alternatives.

.Net Interview Question

PHP Interview Question

Java Interview Question

AngularJS Interview Questions