gpt4 book ai didi

json - MongoDB 在具有未知键的集合中查找

转载 作者:行者123 更新时间:2023-12-05 08:10:13 27 4
gpt4 key购买 nike

我需要查询 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"
}]
}
}
}

最佳答案

您可以尝试使用“$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”表达式。

关于json - MongoDB 在具有未知键的集合中查找,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21423954/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com