I have the following java
code that creates Bson
filters (working as intended).
However when I try to add a projection
to my filter I then get:
'unknown operator: $project' on server
What is the issue here within my code?
private Bson createFilter(String name) {
List<Bson> collectionFilters = new ArrayList<>();
if (name != null) {
filters.add(eq("person_name", name));
}
collectionFilters.add(projectCollectionFields());
return and(collectionFilters);
}
private Bson projectCollectionFields() {
return Aggregates.project(new Document()
.append("_id", new Document("$cond", Arrays.asList(
new Document("$ne", Arrays.asList("$_id", null)),
"$_id",
"$$REMOVE"
)))
.append("name", new Document("$cond", Arrays.asList(
new Document("$ne", Arrays.asList("$person_name", null)),
"$person_name",
"$$REMOVE"
)))
.append("date", new Document("$cond", Arrays.asList(
new Document("$ne", Arrays.asList("$date_added", null)),
"$date_added",
"$$REMOVE"
))));
}