Cross-platform Open Source Non-relational Distributed NoSQL Document-oriented data store BSON: Binary JSON It consumes less space as compared to the text-based JSON.
Each document should have a unique identifier. It
is the _id key. It is similar to the primary key in relational databases.
The _id field is primary key for every document.
It's called _id and is also accessible via id. Attempting to use an id key may result in a illegal ObjectId format error. GridFS : It is used to store binary data. GridFS helps us in storing audio and photographs.
How MongoDB stores movie clips?
It stores the meta data in a collection called file. It then breaks the data into small pieces called chunks and stores it in the chunks collection.
Instead of storing a file in a single document,
GridFS divides the file into parts, or chunks , and stores each chunk as a separate Replication: It provides data redundancy and availability. It helps to recover from hardware failure and service interruptions. Write takes place in the primary replica and then the write is logged in Oplog. Then, Oplog is used by secondary replica members to synchronize their data. Sharding: Large dataset is divided and distributed over multiple servers. Advantage: If we have to insert data, then application needs to access only that shard(piece) which houses that data. MongoDB updates can happen “in place” – The database does not have to allocate and write a full new copy of the object. It does not allocate separate space.
MongoDB disk writes are lazy. If we receive 1,000
increments in one second for the object, it will only be written once. Physical writes occur a couple of seconds after the operation. db.collection.save()
Updates an existing document or inserts a new
document, depending on its document parameter.
The save() method uses either the insert or the
update command If the document does not contain an _id field, then the save() method calls the insert() method. During the operation, the mongo shell will create an ObjectId and assign it to the _id field.
If the document contains an _id field, then the
save() method is equivalent to an update with the upsert option set to true and the query predicate on the _id field.