- Nishant Shrivastava
nishant.nightcrawler@gmail.com
github : nishant-shrivastava
twitter : n1shant
Not Only SQL
Motto :
Code :
$ SELECT fun, profit from `real_world` WHERE `relational` = false;
- Created to store and process very large amounts of data distributed over many machines.
- Still uses keys but they point to multiple columns.
- The columns are arranged by column family.
Examples :
- Instead of tables of rows and columns and the rigid structure of SQL, a flexible graph model is used which, again, can scale across multiple machines.
- NoSQL databases do not provide a high-level declarative query language like SQL to avoid overtime in processing.
- Rather, querying these databases is data-model specific.
Example :
- Inspired by Lotus Notes
- Similar to key-value stores.
- The model is basically versioned documents that are collections of other key-value collections.
- The semi-structured documents are stored in formats like JSON.
- Document databases are essentially the next level of Key/value, allowing nested values associated with each key.
- Document databases support querying more efficiently.
Example :
- Tables
- Collection
- Schema
- Record
- Field
- Collection
- Document
- KeyValuePair
- Connecting to Mongo
- mongo
- (runs as mongod)
- Show Databases
- $ show dbs
- Use Database
- $ use myDb
- Next is CRUD operations....
$ user1 = { first_name : "Nishant" , last_name : "Shrivastava"} ;
$ user2 = { first_name : "Bruce" , last_name : "Wayne"} ;
$ db.users.insert(user1);
$ db.users.insert(user2);
$ show collections;
$ db.users.find();
$ {
"_id" : ObjectId("4c2209f9f3924d31102bd84a") ,
"first_name" : "Nishant" ,
"last_name" : "Shrivastava"
}
{
"_id" : ObjectId("4c2209fef3924d31102bd84b") ,
"first_name" : "Bruce",
"last_name" : "Wayne"
}
- find ()
$ db.collection.find( <query>, <projection> )
- update
- updates single document- can use multi option, can update all documents.
$ db.collection.update( <query>, <update>, <options> )
- save
- performs a special type of update() , depending upon _id
$ db.collection.save( <document> )
- remove ()
$ db.collection.remove( <query>, <justOne>
)