Random Quote

Meio un carton de ovi che un carton nei ovi.

— Me nono

Stack Exchange

profile for Andrea Girardi on Stack Exchange, a network of free, community-driven Q&A sites

Return Distinct Values for an Array Field

The following example returns the distinct values for the field sizes from all documents in the Collection1 collection:

db.getCollection('inventory').distinct('storeCode')

This will be the expected result:

[
     "1502", "1002", "747"
]

Distinct, as for relational database, finds the distinct values for a specified field across a single collection or view and returns the results in an array.