現在,我正在做2個步驟。我想消除其中的一個。如何讓我的MongoDB查詢更高效?
//Get total results, before the limit. I need this number for pagination reasons.
total_rooms = db.rooms.find({'name':'big'}).count();
//Get the actual results
rooms = db.rooms.find({'name':'big'}).skip(start).limit(num)
我在我的網站上到處都是雙重查詢,我感覺真的很無聊。 Mysql只需要我做一個查詢,並給我total_results。
我爲什麼得到-1? – TIMEX
如果你想要的頁數不能消除任何這些查詢。即使您可以以某種方式將它組合起來 - 數據庫仍將在內部執行相同數量的操作。 – keymone
感謝keymone。第一個查詢非常密集? (更好的問題:它與第二個查詢相比有多密集)? – TIMEX