我们遇到了非常奇怪的问题。我们对MongoDB的简单查询需要很长时间才能返回任何文档。数据库已编入索引。我们做了很少的测试,现在他们是:
File.find({sharename: '7iPJUtP2'}, function(err, shares){
console.log(err,shares);
});
console.log会在60秒后触发。
然后我们使用.native()方法:
File.native(function(err, collection){
collection.find({sharename: '7iPJUtP2'}, {})
.toArray(function (err, results) {
console.log(err,results);
});
});
这里console.log在103ms内触发。
我们使用的堆栈是:
有人可以帮忙解决这个问题吗?
更新
File.find({sharename:' 1'})在50ms内执行。
File.find({sharename:' a'})在18000毫秒内执行。
除了sharename字段外,文档是相同的。
答案 0 :(得分:0)
最后我发现了问题。 Mongo查询构建器使查询看起来像Func<context, IQueriable>
instaed
.find({ sharename: /^qwerty$/i }})
。它在最新的MongoDB版本中运行良好,但对于mongo 2.0.1,它不使用索引。
我必须直接在sails-mongo包中解决这个问题。 我已经创建了fork,所以如果有人遇到这个问题你可以使用它。 https://github.com/rparaschak/sails-mongo.git