2016-09-14 68 views
0

我試圖找到在MongoDB中查詢和紅寶石的結果的大小尺寸:找到一個蒙戈::收藏::查看

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> 

如何正確地確定此查詢返回的項目數?我無法在文檔中找到任何信息。

回答

0
collection.find({ foo: 'bar' }).count() 

應該解決您的問題。在mongo中沒有可用的大小方法,但有數量。