gpt4 book ai didi

json - MongoDB 在数组中查找

转载 作者:可可西里 更新时间:2023-11-01 10:01:27 24 4
gpt4 key购买 nike

我有一个 mongodb JSON 数组,但在定位类别时遇到问题,例如。

{ name:"hoyts"}

我已经尝试了 {categories.name:"hoyts"} 和其他几个,但似乎没有任何效果。

这是我的 JSON:

   {
"_id": ObjectId("4f67da1538fc5d7347000000"),
"categories": {
"id": 1,
"name": "hoyts",
"product-logo": "http: \/\/www.incard.com.au\/newsite\/template\/images\/movieticket\/4cinemas\/hoytstop.png",
"products"▼: {
"0": {
"barcode": "25001",
"name": "GoldClass",
"Price": "12.00",
"CashBack": "2.00"
},
"1": {
"barcode": "25002",
"name": "Weekday",
"Price": "12.00",
"CashBack": "2.00"
},
"2": {
"barcode": "25003",
"name": "Weekend",
"Price": "24.00",
"CashBack": "4.00"
}
}
},
"store_name": "movies",
"1": {
"id": 2,
"name": "village",
"logo": "village.png",
"products": {
"0": {
"barcode": "26001",
"name": "GoldClass",
"Price": "12.00",
"CashBack": "2.00"
},
"1": {
"barcode": "26002",
"name": "Weekday",
"Price": "12.00",
"CashBack": "2.00"
},
"2": {
"barcode": "26003",
"name": "Weekend",
"Price": "24.00",
"CashBack": "4.00"
}
}
}
}

最佳答案

在您发布的 JSON 中,类别不是数组,而是对象。如果我们假设您将类别作为数组(在 [] 内),您应该使用 {"categories.name":"hoyts"}(categories.name 带有引号)作为您的标准。如果“类别”不是数组而是对象(但我认为您想要更多类别,因为“属性”的名称是复数),同样的事情也会起作用。

关于json - MongoDB 在数组中查找,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9814655/

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