Get a list of collection indices in Meteor

How to get a list of indexes in a collection using Meteor?
Something similar (or possibly proxy based) Mongo db.collection.getIndexes
There is still not much indexing API in Meteor (in the end, it will be); but I hope someone already solved this problem
Greetings

+5
source share
1 answer

According to this question , you can add getIndexes to a Mongo Collection prototype like this ( @jagi credit):

 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 Mongo db collections directly.

 meteor mongo meteor:PRIMARY> db.tags.getIndexes() [ { "v" : 1, "key" : { "_id" : 1 }, "name" : "_id_", "ns" : "meteor.tags" } ] 
+3
source

Source: https://habr.com/ru/post/1211496/


All Articles