如何根据mgo中的条件结果进行分组

I want to get the result of mgo query performed by grouping certain fields based on result of some condition.

Let say an imaginary document contains three fields fromproductid, toproductid and price

I have the query

bson.M{
        "$group": bson.M{
            "_id": bson.M{
                "productid1": "$fromproductid",
                "productid2": "$toproductid",
            },
            "info": bson.M{
                "$push": "$$ROOT",
            },
        },

Here the grouping is based on first column fromproductid and second column toproductid.

I want to group based on condition like if fromproductid is equal to some productId then productid1 should be fromproductid and productid2 should be toproductid else productid1 should be toproductid and productid2 should be fromproductid