How to make a selection PyMongo only unique records?
>>> db.houses.find({"street":{"$regex": "Fl", "$options":"i"}}).count()
107
>>> for item in db.houses.find({"street":{"$regex": "Fl", "$options":"i"}}):
... print item["street"]
...
Flatbush Avenue
Flatbush Avenue
Flatbush Avenue
Flatlands Avenue
Flatlands Avenue
Flatlands Avenue
Flatlands Avenue
Flatlands Avenue
Flushing Avenue
Flushing Avenue
...more
How to get a unique record only "street" in response to a query? That is, to avoid duplicate records:
Flatbush Avenue
Flatlands Avenue
Flushing Avenue
According to the docs - Cursor.distinct should do the trick:
db.houses.find({"street":{"$regex": "май", "$options":"i"}}).distinct("street")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With