Conditional filtering Summary in MongoDB command mode

Source: Internet
Author: User

Db.tb1.find ()//query all, use it to view the next page.
Db.tb1.find ({"Age": 1})//Check the records of Ages ==1
Db.tb1.find ({},{"age": 1})//Check records for ages ==1
Db.tb1.find ({"name": {$all: ["A", "B"]}})//query name contains a/b record
Db.tb1.find ({"name": {$exists: true}})//query for records that exist in the Name field.
Db.tb1.find ({"Age": {$nin: [12,14]}})//query for records with age that do not contain 12,14 values.
Db.tb1.find ({name)//query name a record with a letter

.......
Summarized as follows:
The query format is as follows: Db.collection.find ({"field": {Operator:val}})
field is Colleciton, operator is the operator, and Val is the comparison value.
Operator are as follows:
$GT, $gte, $lt, $lte: Val? V1.
$all: All there, Val? {V1,v2,v3 ...}
$exists: Exist, Val? True/false;
$ne: Not Equal, Val? V1
$mod: Take the mold. Val? [V1 modulus, v2 remainder]
$in: Contains a value, Val? [V1,v2,v3 ...]
$nin: Does not contain a value, Val? [V1,v2,v3 ...]
$size: Specify an array of lengths, Val? V1
$regex: Regular queries, Val? V1: Wildcard query:/s/, but s/,/is such a syntax error.
JavaScript query: Write function, then query.

>find (condition). Count ()/limit (v)/skip (v)/sort ({"Field": 1/-1},{"Field2": 1/-1} ...)
Paged query, through Limit,skip,sort combination for paging query.
As per page x, page n
> Find (Conditions). SKIP * X). Limit (X). SORT.
Distinct: Queries the different values of the specified key. Db.runcommand ({"distinct": "Collection Name", "Key": "Field Name"})
Group: more complex.

Conditional filtering Summary in MongoDB command mode

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.