MongoDB Common Commands Summary
simple additions and deletions to check the data
Specify the display or not display a field in the query results
For example, we want to find all the data in the lessons collection, but we do not want to include the slides field in the returned result, because slides is a large, base64 array of images that affects the reading of the query results.
Then we can follow a parameter after the query object. As follows:
Db.lessons.find ({}, {slides:0});
You can also explicitly specify which fields are displayed:
Db.bios.find ({},{name:1, contribs:1, _id:0})
Compare operations – greater than and less than
We want to query the data records between StartTime and EndTime, and require that the content contents be numbers 1 to 5.
Db.wemessages.find ({$and: [ {createtime: {$gt: (Starttime.gettime ()/1000). ToString ()}}, {createtime: {$lt: (Endtime.gettime ()/1000). ToString ()}}, {Content: {$in: [' 1 ', ' 2 ', ' 3 ', ' 4 ', ' 5 ']}} );
Here we use $and logical operators, and $GT, $LT, $in comparison operators.
For MongoDB operators, see: http://docs.mongodb.org/manual/reference/operator/query/
update some properties of a record
Using the $set means that only the specified fields are updated, and no other fields are modified, which is generally the intention.
Db.lessons.update ({}, {$set: {' course_id ': ' C.101 '}});
update multiple records
Using {multi:true}, see: Http://www.lai18.com/content/411017.html
Db.lessons.update ({}, {$set: {' course_id ': ' C.101 '}}, {multi:true});d B.muusers.update ({username: ' Tom '}, {$set: { Mobile: ' 6508639713 '}}, {multi:true});
Sorting Query Results
Using the Sort method
Db.muusers.find (). Sort ({firsttime:-1});
-1 Descending, 1 ascending
view query results in a refreshing way
Using the Pretty method
Db.lessons.find ({lesson:1}, {slides:0, mp3voice:0, wavvoice:0, wavvoicemin:0}). Pretty ();
to view a record that does not exist for a field
Use $exists
Db.questions.find ({' sequence_id ': 1, ' pngslide ': {$exists: false}});d B.mycollection.find ({"Price": {"$exists": false } } )
Limit the number of query results, and skip how many records to start Skip
Using Limit and Skip
Db.translation_memory.find ({mp3voice: {$exists: false}}, NULL, {limit:100});
Delete all content in the collection
Using the collection Remove method
Db.collection.remove ();
Get the length of a field in collection
Chained calls
Db.lessons.find ({lesson:1}). ToArray () [0].slides.join ('). length
Collection operation
Renamed Collection
Using the Renamecollection method
Db.quizzes.renameCollection (' questions ');
Delete a field
Use $unset
Db.questions.update ({}, {$unset: {quiz_name:1}}, {multi:true});d b.learning_progress.update ({}, {$unset: {lesson:1}} {multi:true});d b.lessons.update ({}, {$unset: {wavvoice:1, Wavvoicemin:1}}, {multi:true});
Modify the name of a field
Use $rename
Db.students.update ({_id:1}, {$rename: {' nickname ': ' Alias ', ' cell ': ' Mobile '}})
Note: Some MongoDB keywords cannot be used as collection names, for example: group.
"MongoDB Technical Knowledge" series of technical articles organized collection
Basics to get started with 1mongoDB
2MongoDB Getting Started Tutorials (includes installation, common commands, related concepts, tips, common actions, etc.)
3MongoDB Getting Started Tutorial Shard Technology detailed
4MongoDB Introductory tutorials Common operations and Maintenance technology introduction
Example of C # driver operation in 5MongoDB Starter Tutorial
6MongoDB Introductory Tutorial Master-slave replication configuration detailed
Introduction to the aggregation and cursor operations of the 7MongoDB Getting Started tutorial
8MongoDB Getting Started teaching the operation of adding and deleting MongoDB database
An analysis of index operation of 9MongoDB Getting Started tutorial
10MongoDB Getting Started tutorial of the MongoDB database installation diagram under Windows
11MongoDB query field does not create an index caused by Connection Timeout exception solution case sharing
12MongoDB log file is too large a workaround
13MongoDB Community Edition and Enterprise Edition difference comparison table
14MongoDB Chinese Community Initiator takes you to learn MongoDB.
Analysis on performance bottleneck of 15 MongoDB database
The method and performance of 16MongoDB paging query
Cluster architecture implementation of 17MongoDB Shard storage
18Mongodb Bulk deletion of Gridfs file instances
19Mongodb adding, removing Shard server instances
20Mongodb adding, removing Arbiter node instances
MongoDB Installation and configuration tutorial under 21CentOS system
22MongoDB Modifying and deleting a document's Domain property instance
MongoDB basic operations in 23Python: connecting, querying instances
24MongoDB Export Query Results to file example
Things to keep in mind when creating indexes in 25MongoDB
Some pits in 26MongoDB (best not to use)
27 adding user rights to MongoDB sharing method
Simple installation and basic operation of MongoDB under 28Linux system
Basic management commands for the 29MongoDB tutorial
Aggregation of 30MongoDB Tutorials (count, distinct, and group)
Introduction to the index of 31MongoDB tutorials
Data manipulation examples of 32MongoDB tutorials
Basics of getting Started with 33MongoDB tutorials
Examples of query operations for 34MongoDB tutorials
35MongoDB Series Tutorial (iv): Set User access rights
36MongoDB Series Tutorial (eight): Gridfs storage
Introduction to features and advantages of 37MongoDB database
38MongoDB about MongoDB Five features
39MongoDB Series Tutorial (vi): Java operation MongoDB Instance
40MongoDB Series Tutorial (vii): A detailed description of the MONGODB data structure
41MongoDB Series Tutorial (v): MONGO Grammar and MySQL syntax comparison learning
42MongoDB Series Tutorial (ii): About MongoDB
43MongoDB Series Tutorial (i): NoSQL origins
Introduction to MapReduce in 44MongoDB
45MongoDB Series Tutorial (iii): Download and install MongoDB in Windows
46 on how to back up MongoDB
47MongoDB Common Command Summary
48MongoDB and MySQL operation comparison table and the difference introduction
49MongoDB Security Configuration Detailed
Bson Introduction and usage examples in 50MongoDB
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Finishing MongoDB Common Commands Summary