我正在尝试在 MongoDB 和 ruby 中查找查询结果的大小:
size = collection.find({ foo: 'bar' }).size
if size > 0
print "There are #{size} results!"
else
print "There aren't any results."
end
但是,当我运行它时,我收到以下错误:
undefined method `size' for #<Mongo::Collection::View:0x00000004141d48>
如何正确确定此查询返回的项目数?我在文档中找不到任何信息。