【发布时间】:2016-07-16 11:33:15
【问题描述】:
我不确定如何解决这个问题:
我想在 mongoDB 集合中搜索并仅返回适合搜索查询的嵌套对象(对所有字段使用文本搜索)。
集合中的所有文档都具有以下格式:
{
arr: [
{
_id: 1,
name: 'Random',
description: 'Hello world'
},
{
_id: 2,
name: 'World',
description: 'This is a random description'
},
{
_id: 3,
name: 'Random',
description: 'Hi'
}
]
}
在这种情况下,如果我的搜索查询是“世界”,那么结果应该是:
[
{
_id: 1,
name: 'Random',
description: 'Hello world'
},
{
_id: 2,
name: 'World',
description: 'This is a random description'
},
//... objects from other documents in the collection that fits the query
]
如果这在 mongoDB 中是不可能的,是否有任何 JavaScript 库可以实现这一点?非常感谢您的帮助!
【问题讨论】:
标签: javascript mongodb search