MongoDB: What is a good way to get a list of all unique tags?

What is the best way to track unique tags for a collection of documents? The usual way to do tagging seems to be to index multikeys. However, I will often need to get all the unique keys. I do not have access to the new "excellent" mongodb command, since my erlmongo driver does not seem to implement it yet.

+7
mongodb
source share
3 answers

Even if your driver does not implement separate, you can implement it yourself. In JavaScript (sorry, I do not know Erlang, but it should translate quite straightforwardly), it can say:

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

So you: findOne in the "$ cmd" collection of any database that you use. Give it the name of the collection and the key that you want to use separately.

If you ever need a command whose driver does not provide an assistant, you can see http://www.mongodb.org/display/DOCS/List+of+Database+Commands for a somewhat complete list of database commands.

+10
source share

I know this is an old question, but I had the same problem, and I could not find a real solution for it.

So, I came up with this:

http://snipplr.com/view/59334/list-of-keys-used-in-mongodb-collection/

+1
source share

John, you may find it helpful to use Variety, an open source tool to analyze the collection scheme: https://github.com/jamescropcho/variety

Perhaps you can run Variety every N hours in the background and query the newly created sortResults database to get a list of unique keys that start with a given string (i.e. are descendants of a specific parent).

Let me know if you have any questions or need more tips.

Good luck

+1
source share

All Articles