mongodb "$"的作用
Posted konami
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mongodb "$"的作用相关的知识,希望对你有一定的参考价值。
{ "_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 "$"的作用的主要内容,如果未能解决你的问题,请参考以下文章
"if (!(""a"" in window)) { var a = 1; } alert(a); 为什么结果是undefined"(示例代
带有 $sum 操作的 Mongodb 位置运算符“$”不起作用
mongodb 管道 $lookup 中的 $in/$eq 不起作用
C++或C中怎么通过代码执行mongodb中的命令行,把执行结果带回。
@PropertySource(value={"file:conf/application.properties"},encoding = "utf-8")(代