所以我的代码是:
FindIterable<Document> findIterable = collection.find().skip(20).limit(10);
MongoCursor<Document> cursor = findIterable.iterator();
while (cursor.hasNext()) {
Document doc = cursor.next();
// My stuff with documents here
}
cursor.close(); // in finally block
现在我想知道total count
之前的文件skip
和limit
。
完全相同的问题有一个答案,但我有,而且mongo-java-driver v3.1.0
我使用的 API 不同。FindIterable和MongoCursor类中没有方法count()
或没有方法。谢谢!size()
更新
似乎唯一的解决方法是再次调用 mongodb:collection.count
正如@Philipp 所说