MongoDB使用未知密钥在集合中查找

用户名

我需要查询mongodb的帮助,

在我的json中,我需要找到所有带有“ name_color”:“ 8650AC”的项目,我可以找到一个

db.items.find( { "rgDescriptions.230130277_253072421.name_color": "8650AC" } )

但不知道如何找到全部,因为乳清具有不同的键。

怎么做?

 {
  "success": true,
  "rgCurrency": [],
  "rgDescriptions": {
    "230130277_253072421": {
      "appid": "570",
      "classid": "230130277",
      "instanceid": "253072421",
      "icon_url": "Fq3N3-CjKwAJlvOA-3BW3q7hB26k0yVO3FJnn16RCy6QqOUm4btvB75OuSaAEAJDqfsAMfufZUOXXyaOQ4wPbpGh_yypv20ZrBT4TtRQDA-s4BR5-45kTM1IFp9egkQv36-yc6zpfRb6ArwmhgYJQ_-jEC37nzxOiF4qwgDSXCyNqux6quspWb0P6w==",
      "icon_url_large": "Jke-KvK7aqOnDVvaqvGl0Z4LdJu2y2TtcsnPxQ8Q-CGgQpbT86MupBDVEXzRkfFMmRFzxOmHJOA5xI7UEg38YaFLjNm7pyy6Ao9QFIXR_wCcCmeM6ZYl72PTvsUPA8Z_71Oe2_KgO7YGnEJzh42tGsIcZtK5h3q9cJTTkFYC_XXoRJuM66Nn5VTLEHPZkOhBkQ==",
      "icon_drag_url": "",
      "name": "Unusual Enduring War Dog",
      "market_hash_name": "Unusual Enduring War Dog",
      "market_name": "Unusual Enduring War Dog",
      "name_color": "8650AC",
      "background_color": "",
      "type": "\u041a\u0443\u0440\u044c\u0435\u0440, Mythical",
      "tradable": 1,
      "marketable": 1,
      "descriptions": [{
        "type": "html",
        "value": "\u0425\u043e\u0440\u043e\u0448\u043e \u044d\u043a\u0438\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043f\u0435\u0441, \u043d\u0435 \u043f\u043e\u043a\u0438\u0434\u0430\u044e\u0449\u0438\u0439 \u0445\u043e\u0437\u044f\u0438\u043d\u0430 \u0432 \u0441\u0440\u0430\u0436\u0435\u043d\u0438\u0438. \u042d\u0442\u043e\u0442 \u0437\u0432\u0435\u0440\u044c \u043f\u043e\u0432\u0438\u0434\u0430\u043b \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0443\u0436\u0430\u0441\u0430\u044e\u0449\u0438\u0445 \u0434\u0435\u044f\u043d\u0438\u0439 \u0438 \u0432\u0435\u043b\u0438\u043a\u0438\u0445 \u043f\u043e\u0431\u0435\u0434. \u0417\u0430 \u0435\u0433\u043e \u0434\u0435\u0440\u0435\u0432\u044f\u043d\u043d\u043e\u0439 \u043c\u0430\u0441\u043a\u043e\u0439 \u0441\u043a\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0441\u0442\u043e\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043f\u0440\u0430\u0432\u043e\u0441\u0443\u0434\u0438\u0435."
      }, {
        "type": "html",
        "value": "<div style=\"white-space: nowrap; margin: 10px\"><div style=\"white-space: nowrap; padding: 3px;\"><div style=\"width: 60px; height: 32px; vertical-align: top; display: inline-block;\"><div style=\"width: 48px; height: 32px; vertical-align: top; display: inline-block; border: 2px solid rgb(255, 255, 255);>\"><div style=\"position: absolute; width: 48px; height: 32px; vertical-align: top; display: inline-block; background-size: contain; background-image: url(http:\/\/cdn.dota2.com\/apps\/570\/icons\/econ\/sockets\/gem_effect.6be419ef6706ede2de7f6f27ab18748ae3017b60.png)\"><\/div><\/div><\/div><div style=\"vertical-align: top; display: inline-block; margin-left: 12px padding: 2px\"><span style=\"font-size: 18px; color: rgb(255, 255, 255)\">Bleak Hallucination<\/span><br><span style=\"font-size: 12px\">\u041f\u043e\u0442\u0443\u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0439 \u0441\u0430\u043c\u043e\u0446\u0432\u0435\u0442<\/span><\/div><\/div><div style=\"white-space: nowrap; padding: 3px;\"><div style=\"width: 60px; height: 32px; vertical-align: top; display: inline-block;\"><div style=\"width: 48px; height: 32px; vertical-align: top; display: inline-block; border: 2px solid rgb(26, 61, 133);>\"><div style=\"position: absolute; width: 48px; height: 32px; vertical-align: top; display: inline-block; background-size: contain; background-image: url(http:\/\/cdn.dota2.com\/apps\/570\/icons\/econ\/sockets\/gem_color.5a9386e4e99cae2af84385fcb8eea1d0bcf92dcf.png)\"><\/div><div style=\"position: absolute; filter:alpha(opacity=90); -moz-opacity:0.9; -khtml-opacity: 0.9; opacity: 0.9; width: 48px; height: 32px; vertical-align: top; display: inline-block; background-size: contain; background-image: url(http:\/\/cdn.dota2.com\/apps\/570\/icons\/econ\/sockets\/gem_color_mask.c65f0f4e7c1687741863d1e1d675949afd889d5d.png)\"><\/div><\/div><\/div><div style=\"vertical-align: top; display: inline-block; margin-left: 12px padding: 2px\"><span style=\"font-size: 18px; color: rgb(26, 61, 133)\">\u0421\u0438\u043d\u0438\u0439 \u043a\u0440\u0438\u0441\u0442\u0430\u043b\u043b<\/span><br><span style=\"font-size: 12px\">\u041f\u0440\u0438\u0437\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0441\u0430\u043c\u043e\u0446\u0432\u0435\u0442<\/span><\/div><\/div><\/div>"
      }],
      "tags": [{
        "internal_name": "unusual",
        "name": "Unusual",
        "category": "Quality",
        "color": "8650AC",
        "category_name": "\u041a\u0430\u0447\u0435\u0441\u0442\u0432\u043e"
      }, {
        "internal_name": "Rarity_Mythical",
        "name": "Mythical",
        "category": "Rarity",
        "color": "8847ff",
        "category_name": "\u0420\u0435\u0434\u043a\u043e\u0441\u0442\u044c"
      }, {
        "internal_name": "DOTA_Custom_Courier",
        "name": "\u041a\u0443\u0440\u044c\u0435\u0440",
        "category": "Type",
        "category_name": "\u0422\u0438\u043f"
      }, {
        "internal_name": "courier",
        "name": "\u041a\u0443\u0440\u044c\u0435\u0440",
        "category": "Slot",
        "category_name": "\u0422\u0438\u043f"
      }, {
        "internal_name": "DOTA_OtherType",
        "name": "\u0414\u0440\u0443\u0433\u0438\u0435",
        "category": "Hero",
        "category_name": "\u0413\u0435\u0440\u043e\u0439"
      }, {
        "internal_name": "HeroID",
        "name": "1000",
        "category": "HeroID",
        "category_name": "HeroID"
      }]
    },
    "230130201_253034070": {
      "appid": "570",
      "classid": "230130201",
      "instanceid": "253034070",
      "icon_url": "7nco17KZIo5GcLtsZbVQLVY74mb26SzAk7Qvc8BUDd1ocgAus4FmifGo8coe1QSwUSHlOamlbM3YuW5i3UkJnWlzDif7hWTW4eixj0efH4xcLvJxqbQtxZa5OSOeElSOJSRWda6BJ8mwsvLLHJwP4g8sr3L4pzWSzuM1c51CW8E2fwg=",
      "icon_url_large": "CB0CFH5IyIHVJotMrABYsbBRyKU6OMbPAOIfUwnhBUGOGCrtf1CMhmL-werXYAwst0vP-mV0hsJL715CFPwBAY8ZJOQ3VI7Zcr6Br44qFxC6RNiyZWW2wAX-VlJIoAZEkU50tTFVmZAhs8zq3n9WKr4SiexhJ43NALgBVlfwAhbBTyfmaR-MmHY=",
      "icon_drag_url": "",
      "name": "Unusual Fearless Badger",
      "market_hash_name": "Unusual Fearless Badger",
      "market_name": "Unusual Fearless Badger",
      "name_color": "8650AC",
      "background_color": "",
      "type": "\u041a\u0443\u0440\u044c\u0435\u0440, Mythical",
      "tradable": 1,
      "marketable": 1,
      "descriptions": [{
        "type": "html",
        "value": "\u041f\u043e\u0436\u0430\u043b\u0443\u0439, \u043b\u0443\u0447\u0448\u0438\u043c \u043a\u0443\u0440\u044c\u0435\u0440\u043e\u043c \u0438\u0437 \u0432\u0441\u0435\u0445 \u043b\u0435\u0441\u043d\u044b\u0445 \u043e\u0431\u0438\u0442\u0430\u0442\u0435\u043b\u0435\u0439 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0437\u0432\u0430\u0442\u044c \u0431\u0430\u0440\u0441\u0443\u043a\u0430. \u0411\u0443\u0434\u0443\u0447\u0438 \u0431\u0435\u0441\u0441\u0442\u0440\u0430\u0448\u043d\u044b\u043c \u0438 \u0441\u0442\u0440\u0435\u043c\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c, \u043e\u043d \u0441\u0430\u043c\u043e\u043e\u0442\u0432\u0435\u0440\u0436\u0435\u043d\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442 \u043b\u044e\u0431\u043e\u0435 \u043f\u043e\u0440\u0443\u0447\u0435\u043d\u0438\u0435 \u0442\u043e\u0433\u043e, \u043a\u0442\u043e \u0437\u0430\u0441\u043b\u0443\u0436\u0438\u043b \u0435\u0433\u043e \u0434\u043e\u0432\u0435\u0440\u0438\u0435."
      }, {
        "type": "html",
        "value": "<div style=\"white-space: nowrap; margin: 10px\"><div style=\"white-space: nowrap; padding: 3px;\"><div style=\"width: 60px; height: 32px; vertical-align: top; display: inline-block;\"><div style=\"width: 48px; height: 32px; vertical-align: top; display: inline-block; border: 2px solid rgb(255, 255, 255);>\"><div style=\"position: absolute; width: 48px; height: 32px; vertical-align: top; display: inline-block; background-size: contain; background-image: url(http:\/\/cdn.dota2.com\/apps\/570\/icons\/econ\/sockets\/gem_effect.6be419ef6706ede2de7f6f27ab18748ae3017b60.png)\"><\/div><\/div><\/div><div style=\"vertical-align: top; display: inline-block; margin-left: 12px padding: 2px\"><span style=\"font-size: 18px; color: rgb(255, 255, 255)\">Trail of the Amanita<\/span><br><span style=\"font-size: 12px\">\u041f\u043e\u0442\u0443\u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0439 \u0441\u0430\u043c\u043e\u0446\u0432\u0435\u0442<\/span><\/div><\/div><div style=\"white-space: nowrap; padding: 3px;\"><div style=\"width: 60px; height: 32px; vertical-align: top; display: inline-block;\"><div style=\"width: 48px; height: 32px; vertical-align: top; display: inline-block; border: 2px solid rgb(98, 110, 91);>\"><div style=\"position: absolute; width: 48px; height: 32px; vertical-align: top; display: inline-block; background-size: contain; background-image: url(http:\/\/cdn.dota2.com\/apps\/570\/icons\/econ\/sockets\/gem_color.5a9386e4e99cae2af84385fcb8eea1d0bcf92dcf.png)\"><\/div><div style=\"position: absolute; filter:alpha(opacity=90); -moz-opacity:0.9; -khtml-opacity: 0.9; opacity: 0.9; width: 48px; height: 32px; vertical-align: top; display: inline-block; background-size: contain; background-image: url(http:\/\/cdn.dota2.com\/apps\/570\/icons\/econ\/sockets\/gem_color_mask.c65f0f4e7c1687741863d1e1d675949afd889d5d.png)\"><\/div><\/div><\/div><div style=\"vertical-align: top; display: inline-block; margin-left: 12px padding: 2px\"><span style=\"font-size: 18px; color: rgb(98, 110, 91)\">\u0427\u0443\u043c\u043d\u043e\u0439 \u0441\u0435\u0440\u044b\u0439<\/span><br><span style=\"font-size: 12px\">\u041f\u0440\u0438\u0437\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0441\u0430\u043c\u043e\u0446\u0432\u0435\u0442<\/span><\/div><\/div><\/div>"
      }],
      "tags": [{
        "internal_name": "unusual",
        "name": "Unusual",
        "category": "Quality",
        "color": "8650AC",
        "category_name": "\u041a\u0430\u0447\u0435\u0441\u0442\u0432\u043e"
      }, {
        "internal_name": "Rarity_Mythical",
        "name": "Mythical",
        "category": "Rarity",
        "color": "8847ff",
        "category_name": "\u0420\u0435\u0434\u043a\u043e\u0441\u0442\u044c"
      }, {
        "internal_name": "DOTA_Custom_Courier",
        "name": "\u041a\u0443\u0440\u044c\u0435\u0440",
        "category": "Type",
        "category_name": "\u0422\u0438\u043f"
      }, {
        "internal_name": "courier",
        "name": "\u041a\u0443\u0440\u044c\u0435\u0440",
        "category": "Slot",
        "category_name": "\u0422\u0438\u043f"
      }, {
        "internal_name": "DOTA_OtherType",
        "name": "\u0414\u0440\u0443\u0433\u0438\u0435",
        "category": "Hero",
        "category_name": "\u0413\u0435\u0440\u043e\u0439"
      }, {
        "internal_name": "HeroID",
        "name": "1000",
        "category": "HeroID",
        "category_name": "HeroID"
      }]
    }
   }
  }
CodeGroover

您可以尝试使用“ $ where”子句:

db.items.find({"$where" : function(){ 
    for( var c in this ){
        if( c == "rgDescriptions" ){ 
            for(var i in this[c]){ 
                 for(var j in this[c][i]){
                      if(j == 'name_color' && this[c][i][j] == '8650AC'){
                           return true;
                      }
                 }
             }
        };
     }
     return false; 
}});

但是警告您,此子句是“慢速”解决方案,因为每个文档都必须从BSON转换为Javascript对象,然后通过“ $ where”表达式运行。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

MongoDB使用未知密钥在集合中查找

来自分类Dev

在mongodb集合中查找文档对

来自分类Dev

如何使用Express和MongoStore从MongoDB集合中查找会话

来自分类Dev

使用LINQ / C#在MongoDB集合中查找子对象

来自分类Dev

无法使用$ nearSphere从我的mongodb集合中查找数据

来自分类Dev

无法使用$ nearSphere从我的mongodb集合中查找数据

来自分类Dev

在mongodb集合中查找最旧/最新的帖子

来自分类Dev

如何按标签从 secretstorage 集合中查找密钥

来自分类Dev

捕获在Mongodb中的大查找查询期间添加的未知文档

来自分类Dev

在MongoDB集合中的RegEx数组中查找匹配项

来自分类Dev

使用Laravel从集合中查找最大ID

来自分类Dev

使用 LINQ 在嵌套集合中查找值

来自分类Dev

使用 Lodash 从集合中查找重复值

来自分类Dev

使用未知密钥遍历Javascript中的JSON对象

来自分类Dev

如何使用cryptsetup从LUKS中删除未知密钥?

来自分类Dev

在MongoDB中使用一组密钥查找文档

来自分类Dev

使用未知属性名称从集合中获取价值

来自分类Dev

查找集合Java Mongodb中的所有对象

来自分类Dev

在mongodb中查找具有特定字段的所有集合

来自分类Dev

mongodb-查找其他集合中的值计数

来自分类Dev

MongoDB-在集合中查找唯一的名称

来自分类Dev

Mongodb-从聚合查找中的子集合中计数

来自分类Dev

查询以在mongodb图形集合中查找连接的组件?

来自分类Dev

Meteor.js / MongoDB:在集合中查找文档的位置

来自分类Dev

在MongoDB文档集合中查找对象数组内的元素

来自分类Dev

Elasticsearch模板中的未知密钥

来自分类Dev

使用admin SDK从Firestore集合中获取所有密钥

来自分类Dev

Mongodb:查询与未知密钥匹配的文档

来自分类Dev

无法在Node.js应用程序中使用MongoClient在远程mongodb集合中运行“查找”查询

Related 相关文章

  1. 1

    MongoDB使用未知密钥在集合中查找

  2. 2

    在mongodb集合中查找文档对

  3. 3

    如何使用Express和MongoStore从MongoDB集合中查找会话

  4. 4

    使用LINQ / C#在MongoDB集合中查找子对象

  5. 5

    无法使用$ nearSphere从我的mongodb集合中查找数据

  6. 6

    无法使用$ nearSphere从我的mongodb集合中查找数据

  7. 7

    在mongodb集合中查找最旧/最新的帖子

  8. 8

    如何按标签从 secretstorage 集合中查找密钥

  9. 9

    捕获在Mongodb中的大查找查询期间添加的未知文档

  10. 10

    在MongoDB集合中的RegEx数组中查找匹配项

  11. 11

    使用Laravel从集合中查找最大ID

  12. 12

    使用 LINQ 在嵌套集合中查找值

  13. 13

    使用 Lodash 从集合中查找重复值

  14. 14

    使用未知密钥遍历Javascript中的JSON对象

  15. 15

    如何使用cryptsetup从LUKS中删除未知密钥?

  16. 16

    在MongoDB中使用一组密钥查找文档

  17. 17

    使用未知属性名称从集合中获取价值

  18. 18

    查找集合Java Mongodb中的所有对象

  19. 19

    在mongodb中查找具有特定字段的所有集合

  20. 20

    mongodb-查找其他集合中的值计数

  21. 21

    MongoDB-在集合中查找唯一的名称

  22. 22

    Mongodb-从聚合查找中的子集合中计数

  23. 23

    查询以在mongodb图形集合中查找连接的组件?

  24. 24

    Meteor.js / MongoDB:在集合中查找文档的位置

  25. 25

    在MongoDB文档集合中查找对象数组内的元素

  26. 26

    Elasticsearch模板中的未知密钥

  27. 27

    使用admin SDK从Firestore集合中获取所有密钥

  28. 28

    Mongodb:查询与未知密钥匹配的文档

  29. 29

    无法在Node.js应用程序中使用MongoClient在远程mongodb集合中运行“查找”查询

热门标签

归档