mongo脚本:
db.collection1.aggregate([
{
$addFields: {
newColumn:{
$cond: {
if: { $eq:["$query1", 1], $eq:["$query2", 2]},
then: "$find",
else: "not find"
}}
}
}
])
java代码:
AggregationOperation startDateSet = aoc -> new Document("$addFields", new Document("newColumn", new Document("$cond",
new Document("if", new Document("$eq", Arrays.asList("$query1", 1)).append("$eq", Arrays.asList("$query2", 2)))
.append("then", "$find").append("else", "not find")
)));
Aggregation aggregation = Aggregation.newAggregation(
startDateSet,
Aggregation.skip(pageSize * (pageNo - 1)),
Aggregation.limit(pageSize)
);