How to get great values ​​from PyMongo

In MongoDB, I have a repository dataset. Using PyMongo, I find all individual / unique values ​​in the collection

for testy in collection.distinct('stores'):
print(testy)

I can also find a subset of bad memory stores that interest me

for testy in collection.find({'stores': {'$in': ['Aldi','ALDI','aldi']}}):

What I want to do is find unique in this subset

According to MongoDB docs

db.runCommand ( { distinct: "inventory", key: "item.sku", query: { dept: "A"} } )

I tried a lot of combinations, adding a request $in, but cannot make it work.

+4
source share
1 answer

What you are looking for is distinct

for testy in collection.find().distinct('stores'):
    print(testy)

or

for testy in collection.distinct('stores', {'dept': 'A'}):
    print(testy)
+3
source

All Articles