Recently the project has used MongoDB, recently like MongoDB NoSQL database is also relatively hot, write this down, easy to review and learn from you.
The relationship between the data in MongoDB is database,collection,document put into the relational database is the library, table, data.
1. Perform the sudo apt-get install MONGO installation MONGO under Ubuntu.
2. Enter MONGO to enter the database.
View collection (table) show collections;
View data for a student collection
Db.student.find ();
Db.student.find (). ForEach (Printjson);
View third to sixth records
Db.student.find (). Skip (2). Limit (3);
Db.student.find (). ForEach (Printjson); ---Viewing records in JSON format
Inserting data into the student collection
Db.student.insert ({name: "Jack", age:22,score:86});
Delete a piece of data
Db.student.remove ({name: "Jack"});
modifying data
Db.student.update ({name: "Tom"},{$set: {name: "Lubby"}});
Conditional query:
Db.student.find ({score:{$gt: 86}}); Score>86
Db.student.find ({score:{$gte: 86}}); Score>=86
Db.student.find ({score:{$lt: 100}}); score<100
Db.student.find ({score:{$lte: 100}}); score<=100
Db.student.find ({score:{$gt: $lt: 100}}); 87<score<100
Db.student.find ({name:{$ne: "Lubby"}}); Name! = Lubby
Show data that exists for a field
Db.student.find ({name:{$exists: true});
Query mismatch name=b* lead record
Db.users.find ({name: {$not:/^b.*/}});
Regular expression Matching
Sort
Db.student.find (). Sort ({score:1}); Sort by score Ascending
Db.student.find (). Sort ({score:-1}); Sort in descending order of score
There are some similar groups of queries back time to fill up.