2017-02-06 64 views
0

我有如下我的文檔結構的搜索和:執行上主要收集場陣列的對象的同時

{ 
    "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搜索的搜索字段如圖所示下面

enter image description here

現在,parentIdCode沿着我要搜索codeIdproblemCodeproblemNameproblemDescription

如何使用正則表達式查詢子查詢並同時用"$or"子句等標記某些父字段來實現此目的?

回答

0

你可以嘗試這樣的事情。

query = { 
     '$or': [{ 
      "codeId":somevalue 
     }, { 
      "subProblems.codeId": { 
       "$regex": searchValue, 
       "$options": "i" 
      } 
     }, { 
      //rest of sub modules fields 
     }] 
    };