How to make a selection PyMongo only unique records?

mongodb, nosql, pymongo, python

Solution

According to the docs - Cursor.distinct should do the trick:

db.houses.find({"street":{"$regex": "май", "$options":"i"}}).distinct("street")

Problem

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 ```

Original source