简体   繁体   English

在Java MongoDB驱动程序中使用find后如何获得计数?

[英]How to get count after using find with Java MongoDB driver?

I was answered about constructing a MongoDb query 有人回答我关于构造MongoDb查询

How to code collection find with regex and complex criteria using Java MongoDB driver? 如何使用Java MongoDB驱动程序使用正则表达式和复杂条件进行代码收集查找?

Still the question about a count was unanswered: So for this query how to write an analogous Java code returning count: 仍未解决有关计数的问题:因此,对于此查询,如何编写返回计数的类似Java代码:

db.cache.find({objectKey: { $regex: 'Bos*'}, cacheVersionString:'08/03/15_11:05:09'}).count()

With MongoTemplate , it would be something like this: 使用MongoTemplate ,将是这样的:

Query query = new Query();
query.addCriteria(Criteria.where("objectKey").regex("Bos*"));
query.addCriteria(Criteria.where("cacheVersionString").is("08/03/15_11:05:09"));
long count = mongoTemplate.count(query, MyClass.class);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在使用mongoDb java异步驱动程序插入mongoDb集合后获取_id - How to get _id after insertion to mongoDb collection using mongoDb java asynchronous driver 如何使用 java 驱动程序在 MongoDb 中搜索和计算路径值 - How to search and count paths values in MongoDb using java driver MongoDB 如何使用 Java 驱动程序计算数组元素 - MongoDB how to count array elements with Java driver MongoDB:如何使用Java驱动程序获取包含数组的所有元素? - MongoDB : how to get all elements that contain an array using Java Driver? 使用 Java 驱动程序运行 Mongodb 聚合查询时如何获取更新的记录数 - How to get the updated record count when running the Mongodb aggregation queries With Java driver MongoDB Java驱动程序:如何获取开发版本 - MongoDB Java driver: how to get development version 如何使用Java驱动程序3.4+在mongodb中计算带有ObjectId字段的唯一_id? - How to count unique _id with ObjectId field in mongodb using Java driver 3.4+? 如何使用Java驱动程序执行mongodb getShardDistribution() - How to execute mongodb getShardDistribution() using java driver MongoDB异步Java驱动程序find() - Mongodb async java driver find() 使用find() - 使用投影方法,使用mongodb java驱动程序3.4检索数据 - retrieving data with mongodb java driver 3.4 using find()-method with projection
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM