How does one get the list of indexes on a collection with Meteor?
Something similar to (or perhaps based on, proxying) Mongo's db.collection.getIndexes
There's not much of an indexing API in Meteor yet (there will be one eventually); but I hope someone has already solved this problem
Cheers
Asked
Active
Viewed 1,333 times
7

Bogdan D
- 5,321
- 2
- 31
- 32
-
1You can always access the underlying native driver object, or even basically the `Db` object from that. Can be done. Look for that, but I'm letting someone else be the hero if you don't find it yourself first. – Neil Lunn Jan 20 '15 at 10:18
-
You can create indexes with _.map function, of course it's only if you need it to print indexes on website. – sdooo Jan 20 '15 at 13:38
-
@NeilLunn, sounds like a good way to go, I'll eventually look into that, maybe get inspired by the implementation of `_ensureIndex`. @Sindis, I'm not sure we're on the same page (and I'm not talking about website pages :) My question is about indexed fields in Mongo collections. The goal is to call a `find` in the database that looks only in the indexed keys of the collections. Sorry if the question's text was confusing.. – Bogdan D Jan 20 '15 at 14:34
1 Answers
4
According to this issue, you can add a getIndexes
to the Mongo Collection prototype like this (credit to @jagi):
if (Meteor.isServer) {
var Future = Npm.require('fibers/future');
Mongo.Collection.prototype.getIndexes = function() {
var raw = this.rawCollection();
var future = new Future();
raw.indexes(function(err, indexes) {
if (err) {
future.throw(err);
}
future.return(indexes);
});
return future.wait();
};
Items = new Mongo.Collection();
console.log(Items.getIndexes());
}
You can also open the Mongo DB shell and access the Mongo db collections directly.
meteor mongo
meteor:PRIMARY> db.tags.getIndexes()
[
{
"v" : 1,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "meteor.tags"
}
]

Nate
- 12,963
- 4
- 59
- 80