【发布时间】:2015-10-31 16:25:02
【问题描述】:
有人知道如何在 javascript 中返回仅匹配子文档的文档吗?
例如这是数据库记录:
[
{"name":"bestbuy",notes:["article IT", "article 2"]},
{"name":"microsoft",notes:["article IT", "another IT", "article 5"]},
{"name":"IBM",notes:["article 8", "article 9"]}
]
这是我的查询:
collection.find({"company.notes":/IT/}, function(err,result){})
结果是:
[
{"name":"bestbuy",notes:["article IT", "article 2"]},
{"name":"microsoft",notes:["article IT", "another IT", "article 5"]},
]
但我的预期结果是:
[
{"name":"bestbuy",notes:["article IT"]},
{"name":"microsoft",notes:["article IT", "another IT"]}
]
有什么想法吗? 谢谢
【问题讨论】:
-
谢谢,我认为它更具体是 javascript
标签: javascript mongodb