执行以下聚合管道:
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) 我希望反序列化使空数组失败。以下代码有效,但我想让这个特定案例失败:
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)
有什么选择可以实现这一目标?