使用 find() 时 limit() 对我不起作用

Ali*_*yev 0 javascript find limit mongodb

我是 MongoDB 和 Meteor.js 的新手,正在尝试检查集合中是否存在文档。

我知道我可以使用findOneor find({condition}).count(),但是这里的一篇文章指出使用它会更快:

find({condition}).limit(1).size(). 
Run Code Online (Sandbox Code Playgroud)

当我使用类似的东西时

PlayersList.find({'name':"Bill"}).limit(1).size() 
Run Code Online (Sandbox Code Playgroud)

wherePlayersList是一个集合,我收到一条错误消息:“TypeError: undefined is not a function (evaluating 'PlayersList.find({'name':playerName}).limit(1)')”

有人可以解释我做错了什么吗?

小智 5

Metor 中实现的 MiniMongo API 与 Mongo Shell 中实现的 Mongo API 不同。在您的情况下,MeteorJS“minimongo”游标绑定中未实现限制功能。相反,将限制放在 find 函数的选项中。

Posts.find({name:"Bill"}, {limit:1}).count()

查看 http://docs.meteor.com/#find并了解有关查找功能选项的信息。