python:同时查询多个集合

时间:2020-08-16 06:59:05

标签: python-3.x mongodb aggregation-framework

我目前正在努力编写以下代码段,以免花费大量时间处理大量数据。

for chan, branies in zip(channels, branies):
    for bran in branies:
        chan_doc = list(chan_collec.find({'id': chan}, {'reg_id': 1, '_id': 0}))
            if chan_doc:
                reg_doc = list(reg_collec.find({'id': chan_doc[0]['reg_id']}, {'_id': 0, 'id': 0}))
                men_doc = list(men_collec.find({'bran': bran, 'channel_id': chan}).sort("_id",
                                                                                 pymongo.DESCENDING).limit(
                1))
                if men_doc:
                    print("\nChannel: {0} with bran: {1} in the region id: {2} was last targetted on {3} in the region {4}."
                  .format(chan, bran, chan_doc[0]['reg_id'], men_doc[0]['target'], reg_doc[0]['region'])

任何帮助都会很棒!

0 个答案:

没有答案