7

如何使用 Meteor 获取集合中的索引列表?
类似于(或基于代理)Mongo 的 东西 Meteor 中还没有太多的索引 API(最终会有一个);但我希望有人已经解决了这个问题 干杯db.collection.getIndexes

4

1 回答 1

4

根据这个问题,您可以getIndexes像这样向 Mongo Collection 原型添加一个(归功于@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());
}

您还可以打开 Mongo DB shell 并直接访问 Mongo db 集合。

meteor mongo
meteor:PRIMARY> db.tags.getIndexes()
[
  {
    "v" : 1,
    "key" : {
      "_id" : 1
    },
    "name" : "_id_",
    "ns" : "meteor.tags"
  }
]
于 2015-09-29T15:45:50.313 回答