MongoDB Find function usage

Source: Internet
Author: User
Tags mongodb find

MongoDB in Find function syntax: Db.collection.find (QUERY,FILEDS,LIMIT,SIKP)

1. The Qurey parameter is equivalent to the WHERE clause in SQL to indicate the query condition column: Db.account.find ({name: "Lewesyang", age:{$it: 22})

2. The fileds parameter corresponds to the field syntax format after select: db.account.find ({name: "Lewesyang", age:{$it: 22}},{"Age": 0})

The meaning does not return the Age field note (cannot be returned and does not return mixed with both {"Age": 0, "name": 1} is not legal) is recommended either to write or not to return the write

3. Limit parameter limits the number of returned result documents, specifying the maximum number of returned results:

Db.account.find ({name: "Lewesyang", age:{$it: 22}},{"age": 0},5) returns up to 5 legitimate documents

4. Skip parameter when querying document offset:db.account.find ({name: "Lewesyang", age:{$it: 22}},{"age": 0},5,10) return 5 document record 11~16 bar starting from 11th


Use the limit and skip syntax alone: db.account.find (). Limit (5). Skip (Ten)

The Find function query handles documents that are unordered in order to get an ordered document that requires the Sort function syntax:db.account.find (). Sort ({age:-1}) in descending order of age

The return value of the Find function is a cursor object, and the sort function is provided by the cursor object, and the Find function query does not return all legitimate documents at once for the first time to return 101 or 200M of data and cache it to memory . The cursor works. You can use it to sort operations on the result set, thecursor records the access location, and when the in-memory document is accessed, the cursor sends a query data request to the database again





MongoDB Find function usage

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.