I'm trying to implement field level redaction as described in the MongoDB tutorial pages in a Java application.
I'm recieving an error that "both operands of $setIsSubset must be arrays. First argument is of type: string" when the first operand is a $$ reference set in the previous map document. The mapping does seem to work, as when I target a result without the relevant tags I get an expected "object is null" error from the anyElementTrue document.
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<>());
The stored object includes a tags array;
{"_id":{"$oid":"5e9d755207ca65177de4d5ba"},
"name":"Sydney Breakfast",
"notes":"An average tea",
"rating":{"$numberInt":"3"},
"isCaffeine":true,
"tags":["Alpha","Bravo"]}