Finishing Summary of MongoDB Common commands

Source: Internet
Author: User
Tags comparison table create index logical operators mongodb
Summary of MongoDB common commands

simple additions and deletions to check the data

Specify the display in the query results or do not display a field


For example, we want to find all the data in the lessons collection, but we don't want to include the Slides field in the return result, because slides is a huge array of base64-represented images that affect the reading of query results.

Then we can follow the query object with an argument. As follows:

Db.lessons.find ({}, {slides:0});

You can also explicitly specify which fields to display:

Db.bios.find (

{},

{name:1, contribs:1, _id:0}

)

comparison operations – greater than and less than

We want to query the time range between StartTime and Endtime data records, while requiring content to be the number 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 without modifying other fields, which we would normally be.

Db.lessons.update ({}, {$set: {' course_id ': ' C.101 '}});

update more than one record

Using {multi:true}, see: Http://www.lai18.com/content/411017.html

Db.lessons.update ({}, {$set: {' course_id ': ' C.101 '}}, {multi:true});

Db.muusers.update ({username: ' Tom '}, {$set: {mobile: ' 6508639713 '}}, {multi:true});

Sort Query Results

Using the Sort method

Db.muusers.find (). Sort ({firsttime:-1});

-1 Descending, 1 ascending

view query results with refreshing

Using the Pretty method

Db.lessons.find ({lesson:1}, {slides:0, mp3voice:0, wavvoice:0, wavvoicemin:0}). Pretty ();

view records that do not exist in a field

Use $exists

Db.questions.find ({' sequence_id ': 1, ' pngslide ': {$exists: false}});

Db.mycollection.find ({"Price": {"$exists": false}})

limit the number of query results limit and skip the number of records that started skip

Using Limit and Skip

Db.translation_memory.find ({mp3voice: {$exists: false}}, NULL, {limit:100});

Delete all content in collection

Remove method Using Collection

Db.collection.remove ();

Get the length of a field in collection

Chained Call

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});

Db.learning_progress.update ({}, {$unset: {lesson:1}}, {multi:true});

Db.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 sorting collection

1mongoDB Basics to get started

2MongoDB Getting Started tutorial (includes installation, common commands, related concepts, usage tips, common actions, etc.)

3MongoDB Introductory Tutorial on the fragmentation of technology detailed

4MongoDB Introductory tutorials in the common operation and maintenance technology introduction

5MongoDB Introductory Tutorial Examples of C # Drive operations

6MongoDB Introduction Tutorial Master-slave replication configuration detailed

Introduction to aggregation and cursor operations for the 7MongoDB introductory tutorial

8MongoDB Introductory Tutorial elaborate on the additions and deletions of the MongoDB database, check and change operation

Analysis of index operation of 9MongoDB introductory tutorial

10MongoDB Introduction Tutorial Windows MongoDB Database Installation diagram

11MongoDB query field does not create index caused connection Timeout exception solution case sharing

12MongoDB log file too large solution

13MongoDB Community Edition and Enterprise version of the differential comparison table

14MongoDB Chinese Community sponsor to take you to learn MongoDB.

analysis on performance bottleneck of 15 to MongoDB database

the method and performance of 16MongoDB paging query

implementation of cluster architecture for 17MongoDB fragment storage

18Mongodb Bulk Delete gridfs file instance

19Mongodb Add and remove Shard Server instance

20Mongodb Add and remove Arbiter Node instance

tutorial on installation and configuration of MongoDB under 21CentOS system

22MongoDB Modify and delete a document's Domain property instance

MongoDB Basic operation in 23Python: Connection, query instance

24MongoDB Export Query results to file examples

considerations for creating an index in 25MongoDB

some pits in the 26MongoDB (preferably not)

27 Add user rights to MongoDB sharing method

simple installation and basic operation of MongoDB under 28Linux system

Basic management commands for the 29MongoDB tutorial

30MongoDB Tutorial Aggregation (count, distinct, and group)

Index Introduction to the 31MongoDB tutorial

32MongoDB Tutorial Examples of data manipulation

Introductory Basics of 33MongoDB Tutorials

34MongoDB Tutorial Examples of query operations

35MongoDB Series Tutorial (iv): Setting User access rights

36MongoDB Series Tutorials (eight): Gridfs storage Detailed

introduction of characteristics and advantages of 37MongoDB database

38MongoDB Brief Introduction MongoDB five major features

39MongoDB Series Tutorials (vi): Java operations MongoDB Instance

40MongoDB Series Tutorial (vii): MONGODB data Structure detailed

41MongoDB Series Tutorial (v): MONGO Grammar and MySQL grammar comparison learning

42MongoDB Series Tutorials (ii): MongoDB Introduction

43MongoDB Series Tutorials (i): Origins of NoSQL

Introduction to MapReduce in 44MongoDB

45MongoDB Series Tutorials (iii): Downloading and installing MongoDB in Windows

46 talking about the backup way of MongoDB

47MongoDB Summary of COMMON commands

48MongoDB and MySQL operation comparison table and the difference introduction

49MongoDB Security Configuration detailed

Introduction and usages of Bson in 50MongoDB

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.