Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.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
Mongodb 如何设置allowDiskUse:在spring mongoTemplate中为true_Mongodb_Spring Mvc_Spring Data Mongodb_Mongotemplate - Fatal编程技术网

Mongodb 如何设置allowDiskUse:在spring mongoTemplate中为true

Mongodb 如何设置allowDiskUse:在spring mongoTemplate中为true,mongodb,spring-mvc,spring-data-mongodb,mongotemplate,Mongodb,Spring Mvc,Spring Data Mongodb,Mongotemplate,目前我在春季使用mongoDB作为mongoTemplate public List<BasicDBObject> getMoviesByName() { Aggregation aggregation = newAggregation(unwind("movies"), match(where("movies.language").is("english")), sort(Sort.Direction.DESC, "cre

目前我在春季使用mongoDB作为mongoTemplate

public List<BasicDBObject> getMoviesByName() {
    Aggregation aggregation = newAggregation(unwind("movies"), 
            match(where("movies.language").is("english")), 
            sort(Sort.Direction.DESC, "createDate"),
            group(fields().and("_id", "$_id").and("category", "$category")).push("$movies").as("movies"),
            project(fields().and("category", "$category").and("movies", "$movies")).andExclude("_id"));
    AggregationResults<BasicDBObject> groupResults = mongoTemplate.aggregate(
            aggregation, "movieCollection", BasicDBObject.class);
    return groupResults.getMappedResults();
}
我研究了一些帖子allowDiskUse:true是解决方案,我尝试设置为true,但没有结果。请告诉我如何设置上述代码,您可以像下面这样做

MongoClient client = new MongoClient(new ServerAddress("127.0.0.1", 27017));

DB test = client.getDB("test");

DBCollection sample = test.getCollection("sample");

List<DBObject> aggregationQuery = Arrays.<DBObject>asList(
        new BasicDBObject("$sort",new BasicDBObject("score",-1)),
        new BasicDBObject("$limit",1)
);

System.out.println(aggregationQuery);

Cursor aggregateOutput = sample.aggregate(
        aggregationQuery,
        AggregationOptions.builder()
                .allowDiskUse(true)
                .build()
);

//rest of the code

您可以设置聚合选项,如

Aggregation aggregation = newAggregation(…).withOptions(Aggregation.newAggregationOptions().
                        allowDiskUse(true).build());

您是否尝试过
AggregationResults groupResults=mongoTemplate.aggregate(聚合,“movieCollection”,BasicDBObject.class).withOptions(newAggregationOptions().allowDiskUse(true.build())?我试过上面的代码,但没有结果
    Aggregation aggregation = newAggregation(…).
        withOptions(newAggregationOptions().
        allowDiskUse(true).build());
Aggregation aggregation = newAggregation(…).withOptions(Aggregation.newAggregationOptions().
                        allowDiskUse(true).build());