我不确定如何解决这个问题:
我想在 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'
}
]
}
在这种情况下,如果我的搜索查询是“world”,那么结果应该是:
[
{
_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 库可以实现这一点?非常感谢您的帮助!