"MongoDB Learning Note 18" MongoDB query: Find query inline document

Source: Internet
Author: User
Tags mongodb query

Query the embedded document and query the normal document is exactly the same;

For example:

> db.post.find ()    {  "_id"  : objectid ("54ace1394ba07ed75df68f90"),  "Name"  : {  "FirstName"  :  "Joe",  "LastName"  :  "Schome"  },  " Age " : 28 }    { " _id " : objectid (" 54ace14a4ba07ed75df68f91 " ),  "name"  : {  "FirstName"  :  "snail",  "LastName"  :  "Yu"  },   "Age"  : 29 }    {  "_id"  : objectid (" 54ace18d4ba07ed75df68f92 "), " name " : { " FirstName " : " Sunny ", " LastName "  :  "WU"  },  "Age"  : 26 }> db.post.find ({"name": {"FirstName": "Joe", " LastName ":" Schome "})    { " _id " : objectid (" 54ace1394ba07ed75df68f90 "), " Name " : {  FirstName"  :  "Joe",  "LastName"  :  "Schome"  },  "age " : 28 }  &nbsP; > 

Query embedded documents must match exactly, if the order is wrong is not the query;

We can change to "." Pattern to query the embedded document, so that there is no need for exact matching, or the order of irrelevant;

For example:

> Db.post.find ({"Name.firstname": "Joe"}) {"_id": ObjectId ("54ace1394ba07ed75df68f90"), "name": {"FirstName": "Jo E "," LastName ":" Schome "}," Age ": >



This article is from the "Margin with Wish" blog, please be sure to keep this source http://281816327.blog.51cto.com/907015/1600247

"MongoDB Learning Note 18" MongoDB query: Find query inline document

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.