I want to be able to group the documents only if these documents contains same cartId. For example, my order collection look like this(adding cartId field only when user checkout from cart page otherwise no field for cartId(ie empty))
{orderId:1234, qty:1,price:10}
{orderId:1235, qty:1,price:10,cartId:111}
{orderId:1236, qty:3,price:30,cartId:111}
{orderId:1237, qty:2,price:20}
here I want to group the documents having same cartId but don't group the documents having no cartId but it must be in query result as a separate entities. The query result should look like this
[
{orderId:1234, qty:1,price:10} //no cartId
{orderId:111,qt:4,price:40},//grouped two documents and putted orderId as cartId , sum up qty and price
{orderId:1237, qty:2,price:20},//no cartId
]
Thanks in advance