saitama saitama - 8 months ago 94
Python Question

meaning of distinct and how to use it in python(pymongo)

I don't understand what is the meaning of distinct and how use of it. i have search for related answer but it seems like distinct is somehow related to list. really appreciate the help.

list_of_stocks = db.stocks.distinct("symbol")

Answer Source

As the OP confirmed, this is a PyMongo call to a MongoDB database, which allows for a distinct find, in the form of:

db.collection_name.distinct("property_name")

This returns all distinct values for a given property in a collection.

Optionally, if you specify a document filter (effectively a find() filter) as a second parameter, your query will first be reduced by that filter, then the distinct will be applied. For example:

list_of_stocks = db.stocks.distinct("symbol", {"exchange": "NASDAQ"})
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download