MongoCursor没有count()方法?

ala*_*ter 1 java mongodb mongodb-java mongo-java-driver

所以我的代码是:

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
Run Code Online (Sandbox Code Playgroud)

现在我想知道total count之前skip和之前的文件limit.

对于完全相同的问题有一个答案,但我mongo-java-driver v3.1.0和我使用的API是不同的.有没有方法count()size()在这两个FindIterableMongoCursor类.谢谢!

UPDATE

似乎唯一的解决方法是再次打电话给mongodb:collection.count正如@Philipp所说

Phi*_*ipp 7

计数方法,现在可以在找到MongoCollection:

int count = collection.count();
Run Code Online (Sandbox Code Playgroud)

返回集合中的文档总数.

int count = collection.count(criteria);
Run Code Online (Sandbox Code Playgroud)

返回集合中与给定条件匹配的文档数.