I’m working on a page with unique tags used in an image database. Now I wonder if it’s possible to create an index on Mongo db.collection.createIndex() and display the content of the index as an array. I’m assuming that a Mongo index has unique values similar to an index typically found at the end of a book.
Getting a simple array would be nice. Even better would be an array also including the occurrence for of each tag.
ps: At the moment I’m querying a collection on the server and sending the processed list of unique tags as an array via a method. It works fine, but I suspect this is a burden on the server since every time it has to go through all documents (currently 3834) to get a list of unique tags (currently 1691).
Thanks @nlammertyn — just tested your code on a regular collection and it worked.
Unfortunately rawCollection().distinct is still not working on the image collection set up with the Meteor-CollectionFS package. So you’re right, this seems to be the problem.
Any idea what to do? I seem to be unable to find any info how to use rawCollection with CollectionFS.
Aha, you didn’t mention collectionfs. To access the actual meteor collection behind a collectionfs collection (which aren’t the same) you’ll need to access .files. Let me quickly guide you through it.
So if you had setup collectionfs like so:
Files = new FS.Collection("files", {
stores: [fileStore]
});
The way you’d access and run distinct on the actual collection would be: (note the.files)