mongodb get count without repeating find -
when performing query in mongodb, need obtain total count of matches, along documents limited/paged subset.
i can achieve goal 2 queries, not see how 1 query. hoping there mongo feature is, in sense, equivalent sql_calc_found_rows, seems overkill have run query twice. great. thanks!
edit: here java code above.
dbcursor cursor = collection.find(searchquery).limit(10); system.out.println("total objects = " + cursor.count());
i'm not sure language you're using, can typically call count method on cursor that's result of find query , use same cursor obtain documents themselves.
Comments
Post a Comment