- JScript code
{"Activities":[ { "Activity":{ "id":"A_apply", "Name":"apply", "DisplayName":"申请假期" } }, { "Activity":{ "id":"A_manager_check", "Name":"manager_check", "DisplayName":"主管审批" } } ]}
现在查询条件已知"id"="A_apply",可以匹配到Activities的第一个元素,并且返回此结果,而不是整个文档,请问查询语句应该如何写
------解决方案--------------------------------------------------------
测试了一下是可以的,把你的Activity结构简化了一下。
- Assembly code
post={"Activities":[ { "Activity":{ "id":"A_apply", "Name":"apply", "DisplayName":"apply_A" } }, { "Activity":{ "id":"A_manager_check", "Name":"manager_check", "DisplayName":"manage_B" } } ]}db.blog.insert(post)db.blog.find({"Activities.Activity.id":"A_apply"},{"Activities":{"$slice":1}})