我的文档结构如下:
{
"codeId" : 8.7628945723895E13, // long numeric value stored in scientific notation by Mongodb
"problemName" : "Hardware Problem",
"problemErrorCode" : "97695686856",
"status" : "active",
"problemDescription" : "ghdsojgnhsdjgh sdojghsdjoghdghd i0dhgjodshgddsgsdsdfghsdfg",
"subProblems" : [
{
"codeId" : 8.76289457238896E14,
"problemName" : "Some problem",
"problemErrorCode" : "57790389503490249640",
"problemDescription" : "This is edited",
"status" : "active",
"_id" : ObjectId("589476eeae39b20b1c15535b")
},
...
]
}
我有一个搜索字段,应该按codeId
搜索,在搜索字段中基本上用作parentCodeID
,如下所示
现在,与parentIdCode
一起,我想要搜索codeId
,problemCode
,problemName
和problemDescription
。
如何使用正则表达式搜索查询子模块,同时使用"$or"
子句等标记一些父字段以实现此目的?
答案 0 :(得分:0)
你可以尝试这样的事情。
query = {
'$or': [{
"codeId":somevalue
}, {
"subProblems.codeId": {
"$regex": searchValue,
"$options": "i"
}
}, {
//rest of sub modules fields
}]
};