在具有可变键的对象内查询



我有一个对象,我想查询这个词是否存在于对象中,如果是,则返回它。我不知道将用于查询的术语。假设我查询了答案1,然后返回

response:{
"101": "answer1",
"201": "answer2",
"301": "answer3",
"100": "answer4",
"200": "answer5",
"300": "answer6",
"111": "answer7",
"211": "answer8",
"311": "answer9"
}

TIA-

试试这个方法:

db.collection.createIndex( { '$**' : "text" } )
db.collection.aggregate([{$match : { $text: { "$search": "answer1" } }}])

在这里,我们用文本创建索引,然后进行文本搜索。

希望这对你有帮助!

最新更新