MongoCollectionDistinct[MongoCollection[…],f]
obtain a list of distinct values for the field in the collection.
MongoCollectionDistinct[MongoCollection[…],field,query]
obtain a list of distinct values for the field for documents matching query.
MongoCollectionDistinct
MongoCollectionDistinct[MongoCollection[…],f]
obtain a list of distinct values for the field in the collection.
MongoCollectionDistinct[MongoCollection[…],field,query]
obtain a list of distinct values for the field for documents matching query.
Details and Options
- To use MongoCollectionDistinct, you first need to load MongoLink using Needs["MongoLink`"].
- MongoCollectionDistinct returns a List.
- MongoCollectionDistinct corresponds to the db.collection.distinct.
Examples
Basic Examples (1)
Needs["MongoLink`"]client = MongoConnect[]Connect to a new "WolframTestDistinct" collection in the "WolframTestDB" database:
coll = client["WolframTestDB"]["WolframTestDistinct"]data = Dataset[{<|"_id" -> 1, "dept" -> "A", "item" -> <|"sku" -> "111", "color" -> "red"|>, "sizes" -> {"S", "M"}|>,
<|"_id" -> 2, "dept" -> "A", "item" -> <|"sku" -> "111", "color" -> "blue"|>, "sizes" -> {"M", "L"}|>,
<|"_id" -> 3, "dept" -> "B", "item" -> <|"sku" -> "222", "color" -> "blue"|>, "sizes" -> "S"|>,
<|"_id" -> 4, "dept" -> "A", "item" -> <|"sku" -> "333", "color" -> "black"|>, "sizes" -> {"S"}|>}]MongoCollectionInsert[coll, Normal[data]]Find the list of distinct items in the "dept" field:
MongoCollectionDistinct[coll, "dept"]Find the list of distinct items in the "sku" subfield of the "item" field:
MongoCollectionDistinct[coll, "item.sku"]Find the list of distinct items in the "sku" subfield of the "item" field from the set of documents whose "dept" field has value "A":
MongoCollectionDistinct[coll, "item.sku", <|"dept" -> "A"|>]Destroy the collection that was created:
MongoCollectionDrop[coll]See Also
Tech Notes
Related Guides
Text
Wolfram Research (2018), MongoCollectionDistinct, Wolfram Language function, https://reference.wolfram.com/language/MongoLink/ref/MongoCollectionDistinct.html.
CMS
Wolfram Language. 2018. "MongoCollectionDistinct." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/MongoLink/ref/MongoCollectionDistinct.html.
APA
Wolfram Language. (2018). MongoCollectionDistinct. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/MongoLink/ref/MongoCollectionDistinct.html
BibTeX
@misc{reference.wolfram_2026_mongocollectiondistinct, author="Wolfram Research", title="{MongoCollectionDistinct}", year="2018", howpublished="\url{https://reference.wolfram.com/language/MongoLink/ref/MongoCollectionDistinct.html}", note=[Accessed: 15-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_mongocollectiondistinct, organization={Wolfram Research}, title={MongoCollectionDistinct}, year={2018}, url={https://reference.wolfram.com/language/MongoLink/ref/MongoCollectionDistinct.html}, note=[Accessed: 15-June-2026]}