Summary of queries in MONGO

Source: Internet
Author: User
Tags findone

MONGO Simple Query
Db.ansheng.findOne ()//returns the first match to the data
Db.ansheng.findOne ({"AAAAA": 4})
Db.ansheng.find ()//The simplest query
Db.ansheng.find ({"AAAAA": 2})//returns the matched data
Db.ansheng.find ({"AAAAA": 2}). Limit (1)//Returns the specified number of bars (limit) data based on the query criteria (find)
Db.ansheng.find ({"AAAAA": 2}). Skip (1). limit (1);//Hit n data based on query criteria (find), skip previous (skip) bar data, return (limit) bar data
Db.ansheng.find ({"AAAAA": 2}, "book": ["Looking for hope in despair"])
Db.ansheng1.find ({aaa:123, bbb:3211})//Multiple query statements


Returns the specified key
Sometimes it is not necessary to return all key/value pairs in the document, which can be used to return the specified key with the second parameter of find.
Db.ansheng.find ({},{aaaaa:1, list:1})
Db.ansheng.findOne ({},{aaaaa:1, list:1})
By default, _id is always returned, which can be eliminated by using the second parameter.
Db.ansheng.find ({},{_id:0,aaaaa:1})
Db.ansheng.find ({},{_id:0})//If only 0 is entered, all other parameters are returned


Query for the specified scope
In the query we often encounter more than how much
"$lt", "$lte", "$gt", "$gte" correspond respectively
< <= > >=

Summary of queries in MONGO

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.