程序员最近都爱上了这个网站  程序员们快来瞅瞅吧!  it98k网:it98k.com

本站消息

站长简介/公众号

  出租广告位,需要合作请联系站长


+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

暂无数据

MongoCursor 没有 count() 方法?

发布于2022-08-09 23:31     阅读(1019)     评论(0)     点赞(25)     收藏(3)


所以我的代码是:

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之前的文件skiplimit

完全相同的问题有一个答案,但我有,而且mongo-java-driver v3.1.0我使用的 API 不同。FindIterableMongoCursor没有方法count(),也没有方法。谢谢!size()

更新

似乎唯一的解决方法是再次调用 mongodb:collection.count正如@Philipp 所说


解决方案


现在可以在MongoCollection中找到count方法:

int count = collection.count();

返回集合中的文档总数。

int count = collection.count(criteria);

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



所属网站分类: 技术文章 > 问答

作者:黑洞官方问答小能手

链接:http://www.javaheidong.com/blog/article/473273/4b0f255a311c88744ac2/

来源:java黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

25 0
收藏该文
已收藏

评论内容:(最多支持255个字符)