Java 在没有任何查询筛选器的情况下,如何使用ReactiveMongoTemplate对mongodb集合进行计数?
我想在我的JavaSpring应用程序中确定mongodb集合的大小。我知道reactiverectivemongo模板有一个Java 在没有任何查询筛选器的情况下,如何使用ReactiveMongoTemplate对mongodb集合进行计数?,java,mongodb,spring-boot,java-11,reactive-mongo-java,Java,Mongodb,Spring Boot,Java 11,Reactive Mongo Java,我想在我的JavaSpring应用程序中确定mongodb集合的大小。我知道reactiverectivemongo模板有一个count()方法,但它需要一个查询参数 因此,我的解决方案是: public Mono<Long> collectionSize(){ Criteria criteria = Criteria.where("_id").exists(true); return this.reactiveMongoTemplate.coun
count()
方法,但它需要一个查询参数
因此,我的解决方案是:
public Mono<Long> collectionSize(){
Criteria criteria = Criteria.where("_id").exists(true);
return this.reactiveMongoTemplate.count(Query.query(criteria),MY_COLLECTION_NAME);
}
public Mono collectionSize(){
标准=标准。其中(“\u id”)。存在(true);
返回此.reactiveMongoTemplate.count(Query.Query(条件)、我的集合名称);
}
但是我不喜欢这个解决方案,因为我必须使用一个明显的标准
这个问题有没有更好的解决办法
谢谢
标准
的构造函数为空
public Mono<Long> collectionSize(){
Criteria criteria = new Criteria();
return this.reactiveMongoTemplate.count(Query.query(criteria),MY_COLLECTION_NAME);
}
public Mono collectionSize(){
标准=新标准();
返回此.reactiveMongoTemplate.count(Query.Query(条件)、我的集合名称);
}
所有count变量都需要一个查询参数,如文档所示
查询不需要条件,只需提供查询参数即可
public Mono collectionSize(){
返回此.reactiveMongoTemplate.count(新查询(),我的集合名称);
}
public Mono<Long> collectionSize(){
return this.reactiveMongoTemplate.count(new Query(),MY_COLLECTION_NAME);
}