python列表 如何使用 mongodb聚合的类似方法$group筛选

[
     {'_id': ObjectId('5abb4f9ca7e2c54c757b3e48'),
      'amount': 8400,
      'buyerEmail': 'otzYzwMh24edWk8NxSJOqCSZREe0',
      'from': 'weixin',
      'orderDate': datetime.datetime(2018, 3, 28, 8, 17, 28, 940000),
      'orderid': '2018032816173212079',
      'real': 8400,
      'rechargeDate': datetime.datetime(2018, 3, 28, 8, 17, 41, 877000),
      'status': 1,
      'tradeNo': '4200000099201803287230332578',
      'uid': ObjectId('5abb36051a62067bf7e30178')
    },
    {'_id': ObjectId('5b6699f6df03ec3294d7c0a4'),
      'amount': 100,
      'buyerEmail': 'otzYzwC3YwRdu7QrWLXqS3VRJybI',
      'from': 'weixin',
      'orderDate': datetime.datetime(2018, 8, 5, 6, 32, 21, 442000),
      'orderid': '2018080514322245193',
      'real': 100,
      'rechargeDate': datetime.datetime(2018, 8, 5, 6, 33, 0, 381000),
      'status': 1,
      'tradeNo': '4200000148201808052403940202',
      'uid': ObjectId('5a5738411a62061972e128cb')
    },
    .....
]

如何把同一个uid的整合一起,并只显示uid real from rechargeDate的元素?
类似mongodb聚合的$group
理想结果:

[
    {'uid':xxxxxxxxxxxxxxxx:
        [
            {
                'real':xxx,
                'from':xxx,
                'recharge':xxx,
            },
            {
                'real':xxx,
                'from':xxx,
                'recharge':xxx,
            },
            {
                'real':xxx,
                'from':xxx,
                'recharge':xxx,
            },
        ]
    },
        {'uid':xxxxxxxxxxxxxxxx:
        [
            {
                'real':xxx,
                'from':xxx,
                'recharge':xxx,
            },
            {
                'real':xxx,
                'from':xxx,
                'recharge':xxx,
            },
            {
                'real':xxx,
                'from':xxx,
                'recharge':xxx,
            },
        ]
    },
    ...
]
沧海一幻觉
浏览 617回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python