mongodb "$"的作用

來源:互聯網
上載者:User

標籤:而不是   jpeg   logs   find   blog   難度   question   ddr   引用   

{    "_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": "氣血兩虛",    "besttotal": 0,    "bestscore": 0,    "clerkAnswer": [        {            "_id": "p0k94bZ4EHV9XsftlMlOzHS8L",            "clerkId": 2159,            "headerimg": "head/2159/201612/1480922352820.jpeg",            "name": "藥點點店長7",            "content": "高難度",            "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": "藥點店員13",            "content": "但",            "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": "林建麗",            "content": "合生元益生菌",            "createtime": NumberLong(1488302318220),            "adopt": 0,            "score": 0,            "zan": 0,            "ids": [                            ],            "clerkAnswerScore": [                            ],            "qid": "58e48e32830f398e8f401a95",            "status": 0,            "isReward": 0,            "replayAnswers": [                            ]        }    ]}

當要只查詢clerkAnswer這個數組中的某條資料時可以這樣查find({"clerkAnswer._id":"GkJtDMB7uizt699qFyEhAINZ0"},{"clerkAnswer.$":{$slice:1}}) ,如果你在<查詢條件>中查詢的內容是array裡的內容,用$就能引用前查詢中匹配到的元素。所以不需要遍曆就能直接取到數組中的某一個對象。如果把clerkAnswer.$改為clerkAnswer,查詢到的就是三條記錄中的第一條了,而不是前邊指定的那條,當然如果你前邊的查詢條件沒有具體包含到數組裡的資料比如你是這樣查的 find({"_id":ObjectId("58e48e32830f398e8f401a95")},{"clerkAnswer.$":{$slice:1}})這樣就查不到clerkAnswer中指定的某條了


mongodb "$"的作用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.