MongoDB array Query

Source: Internet
Author: User
Tags mongodb commands mongodb query

[Root @ sunrise16 bin] #./mongo

MongoDB shell version: 2.0.0

Insert a document with array elements

Queries documents with a specified value in an array element.

> Db. food. find ({"fruit": {"$ all": ["banana"]})

Queries documents that match the specified array. Make sure that the number and order must be exactly the same; otherwise, the number and order cannot be found.

> Db. food. find ({"fruit": ["banana"]})

Queries documents whose array elements contain multiple specified values, all of which are irrelevant to the order.

> Db. food. find ({"fruit": {"$ all": ["banana", "apple", "peach"]})

Query a document that contains one of multiple values

> Db. food. find ({"fruit": ["banna", "cherry"]})

Queries an array of the specified length. However, you cannot query arrays with a specified length range.

> Db. food. find ({"fruit": {"$ size": 3 }})

Fuzzy query:

Db. collname. find ({"actors. name":/Catterfeld/I}, {"tag": 1, "_ id": 1, "actors": 1 })

 Reference recommendations:

MongoDB query (array, embedded document, and $ where)

Common mongodb commands

MongoDB Query

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.