0 votes
in MongoDB by

What’s a good way to get a list of all unique tags for a collection of documents millions of items large when we doesn't have access to mongodb’s new “distinct” command  in MongoDB?

1 Answer

0 votes
by
The normal way of doing tagging seems to be indexing multikeys. Even if your MongoDB driver doesn’t implement distinct, we can implement.

In JavaScript you can write something like this:

1

result = db.$cmd.findOne({“distinct” : “collection_name”, “key” : “tags”})

 You do a findOne on the “$cmd” collection of whatever database you’re using. Pass it the collection name and the key you want to run distinct on.

If you ever need a command your driver doesn’t provide a helper for, you can look at the below link for complete list of database commands.

https://docs.mongodb.com/manual/reference/command/

Related questions

+1 vote
asked Jun 17, 2020 in MongoDB by AdilsonLima
0 votes
asked Jun 3, 2020 in MongoDB by Robindeniel
...