Give me a MongoDB query

时间:2016-11-09 08:29:09

标签: java spring mongodb hibernate servlets

This is my JSON data:

"tangoRewardList": [

{
    "_id": ObjectId("58107ee67a6e3f0504a2a14c"),
    "brands": [{
        "description": "Tango Card",
        "image_url": "https://dwwvg90koz96l.cloudfront.net/graphics/item-images/tango-card-gift-card.png",
        "rewards": [{
            "description": "Tango Card E-Custom",
            "sku": "TNGO-E-V-STD",
            "currency_code": "USD",
            "available": true,
            "type": "reward",
            "countries": [
                "US"
            ],
            "is_variable": true,
            "min_price": "1",
            "max_price": "500000"
        }]
    }]
}

]

Please give me the MongoDB query to fetch min_price or max_price.

2 个答案:

答案 0 :(得分:0)

db.coll.find({},{"tangoRewardList.brand.minPrice":1,"tangoRewardList.brand.maxPrice":1})

答案 1 :(得分:0)

试试这个

db.collection.aggregate([{"$unwind" : "$tangoRewardList"},{"$unwind" : "$brands"},{$match : {tangoRewardList.brands.min_price : 1}}])
相关问题