db.getCollection('transactions').aggregate([
{ $match:{userId:'12345'}},{$group:
{_id:{
$cond: [{ $eq : [ "$bCardId" , null ] },"$_id","$bCardId"],
$cond: [{ $eq : [ "$cardId" , null ] },"$_id","$cardId"]
},docs: { $push: "$$ROOT" }}}]);
如果bCardId和cardId不存在,则在响应中在null下分组。但是,仅当bCardId或cardId与一条记录的值相同时,才需要将其分组;否则,我应该将一条记录