'Compare data between key of MongoDB using pymongo?

I have a collections like this:

{'_id': ObjectId('6266caf163a028f3c4c574e2'), 'company': 'aaaa', 'name': 'John', 'phone': '55 123 456'}
{'_id': ObjectId('6266caf163a028f3c4aj1s21'), 'company': 'bbbb', 'name': 'Olive', 'phone': '55 987 654'}
{'_id': ObjectId('6266caf163a028f3c4aj1121'), 'company': 'bbbb', 'name': 'Jonathon', 'phone': '66 981 761'}

And I have a list like this;

companyListpython = ['aaaa', 'bbbb', 'cccc']

I need a comparison/data in a for loop like this using pymongo;

for company1 in all_collections:
    for company2 in companyListpython:
        if company1 == company2:
            print(company1, name, phone)
            print("do smt")

Thanks.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source