だから私のコードは次のとおりです。
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クラスとcount()
MongoCursorクラスsize()
の両方にメソッドはありません。ありがとう!
アップデート
collection.count
@Philippが言ったように、唯一の回避策はmongodbへの別の呼び出しを行うことのようです