The role of MongoDB "$"

Source: Internet
Author: User

{    "_id": ObjectId ("58e48e32830f398e8f401a95"),    "_class": "Com.ydd.model.mongdb.WeiXinQuestion",    "OpenID": "Odvo_w2juwmejm7s-uxflasoc0ku21",    "Createtime": Numberlong (1491373618008),    "Endtime": Numberlong (0),    "Antotal": Numberlong (2),    "Content": "Asdfasdfasdfasdfasdf",    "Status": 0,    "Isshow": 1,    "Address": "",    "Sex": 0,    "Labels": "Qi and Blood Two empty",    "Besttotal": 0,    "Bestscore": 0,    "Clerkanswer": [        {            "_id": "p0k94bz4ehv9xsftlmlozhs8l",            "Clerkid": 2159,            "Headerimg": "Head/2159/201612/1480922352820.jpeg",            "Name": "Medicine point shop length 7",            "Content": "High difficulty",            "Createtime": Numberlong (1491373686025),            "Adopt": 0,            "Score": 0,            "Zan": 0,            "IDs": [                            ],            "Clerkanswerscore": [                            ],            "QID": "58e48e32830f398e8f401a95",            "Status": 0,            "Isreward": 0,            "Replayanswers": [                            ]        },        {            "_id": "Gkjtdmb7uizt699qfyehainz0",            "Clerkid": 2166,            "Headerimg": "Head/2166/201701/1484742330434.jpeg",            "Name": "Medicine point Clerk 13",            "Content": "but",            "Createtime": Numberlong (1491373800122),            "Adopt": 0,            "Score": 0,            "Zan": 0,            "IDs": [                            ],            "Clerkanswerscore": [                            ],            "QID": "58e48e32830f398e8f401a95",            "Status": 0,            "Isreward": 0,            "Replayanswers": [                            ]        },        {            "_id": ObjectId ("58b5b0eead349879b2871348"),            "Answerid": "l7izf6lvoyy9qyerd0m2",            "Clerkid": 4625,            "Headerimg": "/resource/2016/8/26/c160c426-a.jpeg",            "Name": "Lin Jianli",            "Content": "co-sheng Yuan Probiotics",            "Createtime": Numberlong (1488302318220),            "Adopt": 0,            "Score": 0,            "Zan": 0,            "IDs": [                            ],            "Clerkanswerscore": [                            ],            "QID": "58e48e32830f398e8f401a95",            "Status": 0,            "Isreward": 0,            "Replayanswers": [                            ]        }    ]}

When you want to query only one piece of data in the Clerkanswer array, you can look for find ({"clerkanswer._id": "Gkjtdmb7uizt699qfyehainz0"},{"clerkanswer.$": {$slice : 1}), if you are querying the contents of the array in < query criteria >, you can refer to the elements that were matched in the previous query using $. So you can take an object directly into the array without traversing it. If you change the clerkanswer.$ to Clerkanswer, the query is the first of the three records, not the one specified in the front, of course, if the query conditions in front of you do not specifically include the data in the array, such as you find ({"_id": O Bjectid ("58e48e32830f398e8f401a95")},{"clerkanswer.$": {$slice: 1}}) This will not find the one specified in the Clerkanswer.

The role of MongoDB "$"

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.