MongoDB Learning Notes (iii)

Source: Internet
Author: User

Query for MONGODB data:

Find Method:

function (Query, field, limit, skip, batchsize, options) {/*query    : Query condition    fields: Returns the column    limit:    Skip:    batchsize:    options: */}
View Code

Querying all data in a collection

Db.user.find (); // When you do not specify a query condition, the default is {} empty document

Specify the fields that need to be returned: By default the _id field is returned, and if you do not want to render the _id field, you can set _id:0 to not return

var key={    "age": 1,    "name": 1}db.user.find ({},key);

Query criteria:

"$lt", "$gt", "$lte", "$gte" operators:

var action={    "age": {"$lte": +, "$GT": +}//20<age<=30} var key={    "_id": 0,// do not return _id, return the age, Name field, other fields do not return    "age" by default : 1,    "name": 1    }db.user.find (action,key);

"$or", "$in" operators:

var action={    "$or":    [        {"$in": [20,25]}},        {"name": {"$ In ": [" Zhang Jie "," Ziyi "]}}    ]}var key=    {" _id ": 0,// do not return _id, return age, Name field, other fields do not return    "age" by default:1    ,"name": 1    }db.user.find (action,key);

"$and" operator:

Cond..

MongoDB Learning Notes (iii)

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.