小编Ham*_*mza的帖子

Spring - mongodb - aggregation - 'cursor'选项是必需的

执行以下聚合管道:

public void getMostLikedItems () {
        UnwindOperation unwind = Aggregation.unwind("favoriteItems");
        GroupOperation group = Aggregation.group("favoriteItems").count().as("likes");
        SortOperation sort = Aggregation.sort(Sort.Direction.DESC, "likes");

        Aggregation aggregation = newAggregation(unwind, group, sort);
        DBObject result = mongoTemplate.aggregate(aggregation, "users", LikedItem.class).getRawResults();
}
Run Code Online (Sandbox Code Playgroud)

抛出以下异常:

com.mongodb.MongoCommandException: Command failed with error 9: 'The 'cursor' option is required, except for aggregate with the explain argument' on server localhost:27017. The full response is { "ok" : 0.0, "errmsg" : "The 'cursor' option is required, except for aggregate with the explain argument", "code" : 9, "codeName" …
Run Code Online (Sandbox Code Playgroud)

java spring mongodb aggregation-framework spring-boot

5
推荐指数
1
解决办法
7540
查看次数

serde 反序列化空数组时如何出错

我希望反序列化使空数组失败。以下代码有效,但我想让这个特定案例失败:

use serde::Deserialize;

#[derive(Debug)]
#[derive(Deserialize)]
struct Doc {
    nums: Vec<i32>
}

fn main(){
    let data = r#"
        {"nums": []}
    "#;
    let doc: Doc = serde_json::from_str(data).unwrap();
    dbg!(doc);
}
Run Code Online (Sandbox Code Playgroud)

有什么选择可以实现这一目标?

rust serde serde-json

3
推荐指数
1
解决办法
264
查看次数