2017-04-06 82 views
0

我在我的集​​閤中有這個文檔,我需要找到哪個字段的值大於20000,對於像這樣的所有文檔。一些字段正在爲集合動態更改。在一個集合中查找哪個字段的大小大於20000(mongodb)

db.doors.find(
    { 
    "doorseller": "e0asda9a0fqqf7-f0asdas66-48c4-bfe5-ssss", 
    "good.Derinlik.value" : {$exists:true}, 
    $where: "this.good.Derinlik.value.length > 20000" 
    } 
) 

這個工程,但我也需要檢查其他領域;但我不想手動爲每個人寫一個查詢。有沒有這方面的方法? 比如我要檢查

-runningStatus 
-good.renkodu.value 

而這個文件正在發生變化,他們的名字對每個文檔。

這是樣板文件

{ 
     "doorseller" : "e0asda9a0fqqf7-f0asdas66-48c4-bfe5-ssss", 
     "_class" : "net.bowl.google.microservice.product.domain.Product", 
     "status" : "MATCHED", 
     "runningStatus" : "running_CREATED", 
     "hasValidImage" : true, 
     "doorID" : "3052007", 
     "door" : "4ef7a893-4158-4b4b-ba60-26cb9f75b988", 
     "good" : { 
      "Ekipman ID" : { 
       "value" : "", 
       "detail" : { 
        "revisedBy" : "door", 
        "revisionDate" : ISODate("2017-02-07T10:13:34.615+0000") 
       }, 
       "history" : [ 
        { 
         "value" : "", 
         "revisedBy" : "door", 
         "revisionDate" : ISODate("2017-02-07T10:13:34.615+0000") 
        } 
       ] 
      }, 
      "Renk Kodu" : { 
       "value" : "", 
       "detail" : { 
        "revisedBy" : "door", 
        "revisionDate" : ISODate("2017-02-07T10:13:34.615+0000") 
       }, 
       "history" : [ 
        { 
         "value" : "", 
         "revisedBy" : "door", 
         "revisionDate" : ISODate("2017-02-07T10:13:34.615+0000") 
        } 
       ] 
      }, 
      "Malzeme" : { 
       "value" : "", 
       "detail" : { 
        "revisedBy" : "door", 
        "revisionDate" : ISODate("2017-02-07T10:13:34.615+0000") 
       }, 
       "history" : [ 
        { 
         "value" : "", 
         "revisedBy" : "door", 
         "revisionDate" : ISODate("2017-02-07T10:13:34.615+0000") 
        } 
       ] 
      }, 
      "doorID" : { 
       "value" : "3052007", 
       "detail" : { 
        "revisedBy" : "admin", 
        "revisionDate" : ISODate("2017-02-10T07:15:05.405+0000") 
       }, 
       "history" : [ 
        { 
         "value" : "3052007", 
         "revisedBy" : "door", 
         "revisionDate" : ISODate("2017-02-07T10:13:34.615+0000") 
        }, 
        { 
         "value" : "3052007", 
         "revisedBy" : "admin", 
         "revisionDate" : ISODate("2017-02-10T07:15:05.405+0000") 
        } 
       ] 
      }, 
      "Garanti Notu" : { 
       "value" : "", 
       "detail" : { 
        "revisedBy" : "door", 
        "revisionDate" : ISODate("2017-02-07T10:13:34.615+0000") 
       }, 
       "history" : [ 
        { 
         "value" : "", 
         "revisedBy" : "door", 
         "revisionDate" : ISODate("2017-02-07T10:13:34.615+0000") 
        } 
       ] 
      }, 
      "Derinlik" : { 
       "value" : "", 
       "detail" : { 
        "revisedBy" : "door", 
        "revisionDate" : ISODate("2017-02-07T10:13:34.615+0000") 
       }, 
       "history" : [ 
        { 
         "value" : "", 
         "revisedBy" : "door", 
         "revisionDate" : ISODate("2017-02-07T10:13:34.615+0000") 
        } 
       ] 
      } 
      }} 

回答

1

我可以建議簡單的JavaScript代碼,您可以在DBshell運行:

var keys = []; 

db.doors.find({}).forEach(function(doc){ 
    for (var key in doc){ 
     if(typeof(doc[key]) == 'number' && doc[key] > 20000){ 
     keys.push({"doc.id": doc._id, "key":key, "value":doc[key]}); 
     } 
    } 
}); 
print(keys); // prints all the results 

注:

  1. 的doc.id是。的標識符當你有很多文件時,你可以使用特定文件
  2. 上面的腳本在值相同的深度(0級)上是好的。
+0

它不是數字。我想檢查字符串的長度或其他。他們不在相同的水平:( – mark

相關問題