0

我正在尝试按照Java 应用程序中的MongoDB 教程页面中的描述实现字段级别的编辑。

当第一个操作数是在前一个地图文档中设置的 $$ 引用时,我收到一个错误,即“$setIsSubset 的两个操作数都必须是数组。第一个参数的类型是:字符串”。映射似乎确实有效,因为当我以没有相关标签的结果为目标时,我从 anyElementTrue 文档中得到预期的“对象为空”错误。

List<String> userAccess = Arrays.asList("Delta");

    List<Document> results = collection.aggregate(Arrays.asList(
            match(eq("_id", new ObjectId(id))),
            new Document("$redact", 
              new Document("$cond", Arrays.asList(
                new Document("$anyElementTrue",
                  new Document("$map",  new Document("input", "$tags")
                    .append("as", "objectAccess")
                    .append("in",
                      new Document("$setIsSubset", Arrays.asList("$$objectAccess", userAccess)))))
            ,"$$KEEP", "$$PRUNE" )))
    )).into(new ArrayList<>());

存储的对象包括标签数组;

{"_id":{"$oid":"5e9d755207ca65177de4d5ba"},
  "name":"Sydney Breakfast",
  "notes":"An average tea",
  "rating":{"$numberInt":"3"},
  "isCaffeine":true,
  "tags":["Alpha","Bravo"]}
4

0 回答 0