Created by Muhammad Akif
almost 7 years ago
|
||
What is mongo db? MongoDb document based no-sql database. To query mongodb we use json. Benefits: i) Programmers only need to create a data model that fits there application. ii) mongodb predicates on data models to it is easy to shard data or distribute data on multiple servers. iii) Supports scaling out feature. iv) We dont need to depend on deployment model.it can deployed easily on one server or one node,a few nodes or a hundred of shards. v) In MongoDB, a write operation is atomic on the level of a single document, even if the operation modifies multiple embedded documents within a single document.When a single write operation modifies multiple documents, the modification of each document is atomic, but the operation as a whole is not atomic and other operations may interleave.
Mongo Shell Node js communicate with mongodb using v8 js. V8 is written in c++. Other way to communicate with mongo db is through mongo shell which is written in c++ when we enter commands it interprets using its own v8 bindings.
BSON(Binary JSON): Node js communicate with mongo db using bson data format. mongo send and receive data in bson format. 1)Lightweight 2) Traversable. 3) Efficient Difference between json and bson is that bson support more datatypes as compare to json. If you create a new document without an _id field, MongoDB automatically creates the field and assigns a unique BSON ObjectId. BSON plays the role of a canonical (i.e., "unique") representation of documents shared across all drivers and tools.
CURD using a mongo db query language. db is a global variable used to set current database. help command used check available commands. use now db point to dbname. switched to defined db. if exist only switch otherwise create new db. same with collections. find() return all documents. find({}) return all documents. find({your constraints}); returned all records matching constraints. Find command is only a array of document but it is a cursor object. Shell is a javascript interpreter we can write javascript in the shell. var c = db.collection.find(); return a cursor to records which is stored in variable c; c.hasNext(); return true if next record is available and false if no row in next. c.next(); return that document.
Want to create your own Notes for free with GoConqr? Learn more.