MongoDB Basic
MongoDB Basic
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.
Mongodb provides official driver support for C, C++, C#, Java, Node.js, Perl, PHP, Python, Ruby,
Scala, Go and Erlang.
You can use MongoDB with any of the above languages. There are some other community
supported drivers too but the above mentioned ones are officially provided by MongoDB.
3) What are the different types of NoSQL databases? Give some example.
There are many NoSQL databases. MongoDB, Cassandra, CouchBD, Hypertable, Redis, Riak,
Neo4j, HBASE, Couchbase, MemcacheDB, Voldemort, RevenDB etc. are the examples of NoSQL
databases.
MongoDB is better than other SQL databases because it allows a highly flexible and scalable
document structure.
For example:
MongoDB database are faster than SQL databases due to efficient indexing and storage
techniques.
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.
We can achieve primary key-foreign key relationship by embedding one document inside
another. For example: An address document can be embedded inside customer document.
2 byte process id
3 byte counter
20) Does MongoDB need a lot space of Random Access Memory (RAM)?
MongoDB client drivers supports all the popular programming languages so there is no issue of
language, you can use any language that you want.
Yes. MongoDB databases have dynamic schema. There is no need to define the structure to create
collections.
MongoDB's cache is not configurable. Actually MongoDb uses all the free spaces on the system
automatically by way of memory mapped files.
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.
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.
28) 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.
The fields used in the query are part of an index used in the query.
Covered query makes the execution of the query faster because indexes are stored in RAM or
sequentially located on disk. It makes the execution of the query faster.
Covered query makes the fields are covered in the index itself, MongoDB can match the query condition
as well as return the result fields using the same index without looking inside the documents.
A replica can be specified as a group of mongo instances that host the same data set. In a replica set,
one node is primary, and another is secondary. All data is replicated from primary to secondary nodes.
In MongoDB, primary nodes are the node that can accept write. These are also known as master nodes.
The replication in MongoDB is single master so, only one node can accept write operations at a time.
Secondary nodes are known as slave nodes. These are read only nodes that replicate from the primary.
Create
Read
Update
Delete
37) What will happen when you remove a document from database in MongoDB? Does MongoDB
remove it from disk?
Yes. If you remove a document from database, MongoDB will remove it from disk too.
MongoDB doesn't follow file system fragmentation and pre allocates data files to reserve space while
setting up the server. That's why MongoDB data files are large in size.
A storage engine is the part of a database that is used to manage how data is stored on disk.
For example: one storage engine might offer better performance for read-heavy workloads, and another
might support a higher-throughput for write operations.
A database profiler is used to collect data about MongoDB write operations, cursors, database
commands on a running mongod instance. You can enable profiling on a per-database or per-instance
basis.
The database profiler writes all the data it collects to the system. profile collection, which is a capped
collection.
No. it is not possible to configure the cache size for MMAPv1 because MMAPv1 does not allow
configuring the cache size.
For the WiredTiger storage engine, you can specify the maximum size of the cache that WiredTiger will
use for all data. This can be done using storage.wiredTiger.engineConfig.cacheSizeGB option.
Redis has a key-value storage whereas MongoDB has a document type storage.
Triggers are not available in MongoDB while triggers are available in CouchDB.
MongoDB serializes JSON data to BSON while CouchDB doesn't store data in JSON format.
MongoDB is easy to administer in the case of failure while Cassandra provides high availability with no
single point of failure.
You don't need to create a database manually in MongoDB because it creates automaically when you
save the value into the defined collection at first time.