带有$ filter和$ setIsSubset聚合组成的Spring Data MongoDB $ project

时间:2019-05-10 01:22:12

标签: spring-data spring-data-mongodb

我具有以下文档架构:

{
  "_id": "23423242",
  "props": [
    {
      "name": "test1",
      "valueSet": ["hi", "hello"]
    },
    {
      "name": "test2,
      "valueSet": ["morning!", "hola"]
    }
  ],
  "description": "some description"
}

我让原始JS按照我想要的方式工作,即

var greetings = ["hi", "hello", "chao"];

var removeNotMatching = {
  "_id": "$_id",
  "props": {
     "$filter": {
       "input": "$props",
       "as": "prop",
       "cond": {
         "$setIsSubset": ["$$prop.valueSet", greetings]
       }
     }
  },
  "description": "$description"
};

如何将其转换为project一部分的newAggregation(MyType.class, ....)之类的方法

我想使用最新的Spring Data运算符,包括AggregationExpression

到目前为止,我是这样的:

List<String> greetings = Arrays.asList("hi", "hello", "chao");

TypedAggregation<MyType> aggregation = newAggregation(MyType.class,
  project()
     .and("id").as("id")
     .and("props")
        .filter("prop", SetIsSubset
            .arrayAsSet("prop.valueSet")
            .isSubsetOf(????)
        .as("props")
     and("description").as("description"));

不太确定我是否走在正确的轨道上,也不确定如何将greetings列表包括到聚合中。

任何帮助将不胜感激。

谢谢!

0 个答案:

没有答案