Meteor.js - 使用提示让 Mongo 使用索引? [英] Meteor.js - Use hint to make Mongo use index?

查看:47
本文介绍了Meteor.js - 使用提示让 Mongo 使用索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Meteor 查询 MongoDB 集合.查询当前使用了错误的索引.使用原始 Mongo,可以将 hint 传递给查询使用指定的索引.有没有办法直接从 Meteor 中做到这一点?

I'm using Meteor to query a MongoDB collection. The query is currently using the wrong index. With raw Mongo, it is possible to pass a hint to a query to use a specified index. Is there any way to do this from within Meteor directly?

推荐答案

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

This can be done directly inside of Meteor using the $query: $hint: syntax. It is worth noting that using the sort option instead of $orderBy: seems to cause Meteor to complain.

示例:

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 会抱怨收到错误提示.

Make sure that the index that you are specifying in your hint actually exists in your db or else mongo will complain about receiving a bad hint.

这篇关于Meteor.js - 使用提示让 Mongo 使用索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆