Reputation: 563
is it possible to exclude fields of nested Documents in Spring Data MongoDB?.
If tried it with
query.fields().exclude("user.password");
but that ends with the hole user document be excluded.
Upvotes: 4
Views: 4271
Reputation: 2000
You can achieve that using Aggregation and ProjectOperation.
ProjectionOperation projectionOperation = project().andExclude("user.password");
mongoTemplate.aggregate(Aggregation.newAggregation(projectionOperation);
Upvotes: 9