查询转换从mongodb到Spring Boot失败

时间:2019-04-04 07:50:12

标签: spring mongodb spring-boot

我的包含查询和项目命令的聚合查询可在mongo终端上运行,但是通过Spring Boot我无法使其正常运行。

db.categories.aggregate([
{
 $lookup:
   {
     from: "brands",
     localField: "brands",
     foreignField: "_id",
     as: "brands"
   }
},
{
  $project: {"brands.categories": 0}
}
])

这是弹簧靴的方式

fun lookupOperation(): MutableList<CategoryDocument> {
    val lookupOperation = LookupOperation.newLookup()
            .from("brands")
            .localField("brands")
            .foreignField("_id")
            .`as`("brands")

    val project = Aggregation.project().andExclude("brands.categories")
    val aggregation = Aggregation.newAggregation(lookupOperation, project)

    return mongoTemplate.aggregate(aggregation,  "categories", CategoryDocument::class.java).mappedResults
}

0 个答案:

没有答案