MY mongo cli查询
{$project:{"userId":{$setIntersection:["array1","array2"]}}}
我想将其转换为春季聚合投影。
我写以下查询
var intersection=SetOperators.arrayAsSet("array1").intersects("pipe1","pipe2")
var afterFacetStage=Aggregation.project().and(intersection).`as`("userId")
这等效于
{$project:{"userId":{$setIntersection:["array1","pipe1","pipe2"]}}}
没想到我不想包含arrayAsSet
看到SetOperator类代码后,我找到了另一种方法
var intersectOperation=SetOperators.SetOperatorFactory("array1").intersects("pipe1","pipe2")
var afterFacetStage1=Aggregation.project().and(intersectOperation).`as`("userId")
仍会生成此意外查询
{$project:{"userId":{$setIntersection:["array1","pipe1","pipe2"]}}}