Javascript 查找哪个字段';集合中的大小大于20000(mongodb)

Javascript 查找哪个字段';集合中的大小大于20000(mongodb),javascript,mongodb,Javascript,Mongodb,我的收藏中有这个文档,我需要找到像这样的所有文档中哪个字段的值大于20000。集合的某些字段正在动态更改 db.doors.find( { "doorseller": "e0asda9a0fqqf7-f0asdas66-48c4-bfe5-ssss", "good.Derinlik.value" : {$exists:true}, $where: "this.good.Derinlik.value.length > 20000" } ) 这是可行的

我的收藏中有这个文档,我需要找到像这样的所有文档中哪个字段的值大于20000。集合的某些字段正在动态更改

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")
                    }
                ]
            }
            }}

我可以建议您在DBshell中运行简单的javascript代码:

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
注意事项:

  • 当您有许多文档时,doc.id是特定文档的标识符
  • 当值位于相同深度(级别0)时,上面的脚本效果良好

  • 这不是数字。我想检查一下字符串的长度或其他什么。而且它们不在同一水平:(