比较两个集合并返回缺失的集合

时间:2019-08-07 13:31:42

标签: python pymongo

我正在使用pymongo,并且我有一个collectionNamesCollection,我已经运行了一个查询,该查询创建了一个新的集合DifferentCollection,但是我想我可能错过了一些。我想看看是否可以找到我错过的那些。这是我的代码:

def get_names_to_lookup():
    #get all company names to look up
    names_to_look_up_temp = []
    doc_cursor = NamesCollection.find({"Status" : "Active"})
    for x in doc_cursor:
        names_to_look_up_temp.append(x.get('Name'))
    names_to_look_up_temp = list(set(names_to_look_up_temp))

    names_already_looked_up = []
    names_already_looked_up_cursor = DifferentCollection.find({})
    for name in names_already_looked_up_cursor:
        names_already_looked_up.append(name.get('name'))

    names_to_look_up = []
    for name in names_to_look_up_temp:
        if name not in names_already_looked_up:
            names_to_look_up.append(name)

test = get_company_names_to_lookup()

有更快的方法吗?

0 个答案:

没有答案