我想对mongoDB集合进行$ text $ search,其中文档的字段是字段数组。
我的查询由于某种原因返回了false。无法弄清楚,因为我已经在集合中的“ conditions.description”上添加了索引。
{
"_id": "58f9c87b5246af0aac145ew",
"total": 2,
"patientId": "xxxxxxx",
"conditions": [
{
"verificationStatus": "confirmed",
"dateRecorded": "2017-03-14",
"clinicalStatus": "active",
"description": "Afib"
},
{
"verificationStatus": "confirmed",
"dateRecorded": "2017-03-14",
"clinicalStatus": "active",
"description": "Arterial hypertension"
}
]
}
.find({
"$and": [
{ "patientId": { $eq: pID } },
{ "conditions.description": { $text: { $search: "diabetes hypertension" }, $caseSensitive: false } }
]
})
答案 0 :(得分:0)
根据documentation,您没有提供$text
搜索的字段:
db.getCollection('YourCollection').find({
"$and": [
{ "patientId": { $eq: pID } },
{ $text: { $search: "diabetes hypertension" } }
]
})