distinct() - Find distinct values command
Finds distinct values for the submitted query.
Syntax diagram
Command parameters
- attribute
- This string parameter specifies the field for which to find distinct values. It can be a string data type or an object.
- query
- This optional string parameter specifies a filter for selecting a subset of documents.
- limit
- This optional string parameter returns at most the specified number of documents from the result set.
- offset
- This optional string parameter finds the document that the query requested after skipping a specified number of rows.
Example
Example 1: Issue an SQL query:
db.books.distinct("author")
Sample output is as follows: [christie, granger, marsh]
Example 2: Get distinct values for the state and
city, with no limit on the results, but skip the first three rows:
db.books.distinct({"state":1, "city":1}, {}, 0, 3)
Sample output is as follows: Row 1:
{ state: AZ,
city: AB
}
Row 2:
(...)