【问题标题】:Meteor.js - Use hint to make Mongo use index?Meteor.js - 使用提示让 Mongo 使用索引?
【发布时间】:2015-04-28 04:36:07
【问题描述】:

我正在使用 Meteor 查询 MongoDB 集合。该查询当前使用了错误的索引。使用原始 Mongo,可以将 hint 传递给查询以使用指定的索引。有没有办法直接在 Meteor 中执行此操作?

【问题讨论】:

    标签: meteor


    【解决方案1】:

    这可以使用 $query: $hint: 语法直接在 Meteor 内部完成。值得注意的是,使用排序选项而不是 $orderBy: 似乎会导致 Meteor 抱怨。

    例子:

    Meteor.collection.find( 
        {  $query:{
            //query goes here
        }, $hint: {
            "indexField1": 1, "indexField2": 1, "indexField3": -1
        }, $orderBy:{
            "createdAt": -1 //sorting option
        }
    },
        {limit:30} //sort here makes Meteor complain
    );
    

    确保您在提示中指定的索引确实存在于您的数据库中,否则 mongo 会抱怨收到错误提示。

    【讨论】:

      【解决方案2】:

      快速浏览一下 meteor-mongo warpper 代码,我看不到它。 但是,meteor 可以使用整个 node.js 驱动程序(参见 findAndModify https://github.com/meteor/meteor/issues/1070 的类似问题)。

      而且,提示在 node.js 驱动程序中肯定是可用的,所以也许构建自己的包装器会是解决方案?我还没有穿过这座桥,所以我不能提供更明确的解决方案,但这可能是一个很好的起点(对于一个包来说也是一个好主意!)。

      【讨论】:

        猜你喜欢
        • 2014-01-11
        • 2015-03-24
        • 1970-01-01
        • 1970-01-01
        • 2012-04-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-03-31
        相关资源
        最近更新 更多