聚合意外的令牌:

时间:2018-05-20 15:46:03

标签: mongodb mongodb-query aggregation-framework

聚合mongodb查询下面给出了

  

意外的令牌:错误

db.getCollection("products_data").aggregate(
    {
        "$unwind": {
            "path": "$color",
            "preserveNullAndEmptyArrays": true
        }
    },
    {
       "$match":{
        "country":"UK",
        "$or":[{
            "$and":[
                "$or":
                    [{
                        "$and":[
                            {"status":"drafted"},
                            {"color":{$in:["blue"]}}
                        ]},
                        {"$and":[
                            {"status1":"complete"},
                            {"status2":{$nin:["n/a","drafted","complete"]}},
                            {"color":{$in:["green"]}}

                    ]}
                ]
            ]
            },{
            "$and":[
                "$or":
                    [
                       { "$and":[
                            {"status":"drafted"},
                            {"color":{$in:["blue"]}}
                        ]},
                        {"$and":[
                            {"status1":"complete"},
                            {"status2":{$nin:["n/a","drafted","complete"]}},
                            {"color":{$in:["green"]}}

                    ]}
                ]
            ]
            }
        ]
       }

    },


    {
    "$group":{
        "_id":"$field",
        "products":{$sum: 1},
        "bid":{"$push":"$product_id"}
    }
},
{
    "$project":{
        "field":"$_id",
        "products":"$products",
        "bid":1,
        "_id":0
    }
}
);

获取给定指定条件的聚合计数。

0 个答案:

没有答案