Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在没有任何查询筛选器的情况下,如何使用ReactiveMongoTemplate对mongodb集合进行计数?_Java_Mongodb_Spring Boot_Java 11_Reactive Mongo Java - Fatal编程技术网

Java 在没有任何查询筛选器的情况下,如何使用ReactiveMongoTemplate对mongodb集合进行计数?

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

我想在我的JavaSpring应用程序中确定mongodb集合的大小。我知道reactiverectivemongo模板有一个
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);
    }