如何测试_ensureIndex是否工作

How test if _ensureIndex is working?

本文关键字:ensureIndex 是否 工作 测试 何测试      更新时间:2023-11-08

有没有办法显示索引,看看它是否正常工作?谢谢

我正在启动时构建它:

// create a compound index
if (Meteor.isServer) {
    Meteor.startup(function() {
        MyPix.files._ensureIndex({'metadata.tags': 1, 'original.name': 1, 'uploadedAt': -1})
    })
}

您可以通过meteor mongo 进行连接

然后运行

show collections

选择对应于MyPix的集合,比如说mypix

db.mypix.getIndexes();

您可以使用mongodb的getIndexes方法。

meteor mongo
db.files.getIndexes()

或者您可以使用mongodb的游标解释。

meteor mongo
db.files.find(<query>).explain()

不确定其中是否有任何一个是正确的,但两者似乎都返回空数组。这是否意味着没有索引?

meteor:PRIMARY> show collections
cfs.MyPix.filerecord
cfs._tempstore.chunks
system.indexes
meteor:PRIMARY> db.cfs.MyPix.getIndexes()
[ ]
meteor:PRIMARY> db.MyPix.getIndexes()
[ ]