嘿,
我需要一些帮助将以下 MongoDB 查询转换为 MongoDB Java 驱动程序查询。
请注意,查询有效。
db.days.aggregate([
{ $match: { 'day' : 'March_1'}},
{ $project: {
_id : 0,
day: 1,
events: {$filter: {
input: '$events',
as: 'event',
cond: {$eq: ['$$event.year', '2002']}
}}
}}
])
Run Code Online (Sandbox Code Playgroud)
我的尝试是这样的,但失败了,我需要你的帮助。
Document query = new Document("$match", new Document("day", day)).
append("$project", new Document("_id", 0).
append("day", 1).
append("events", new Document("$filter", new Document(
"input", "$" + category).
append("as", "event").
append("cond", new Document("$eq", Arrays.asList("$$event.year", year))))));
Run Code Online (Sandbox Code Playgroud)
我得到的错误是
"{ "ok" : 0.0, "errmsg" : "A pipeline stage specification object …Run Code Online (Sandbox Code Playgroud)