4

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.

1 Answer 1

9

You can achieve that using Aggregation and ProjectOperation.

ProjectionOperation projectionOperation = project().andExclude("user.password"); 
mongoTemplate.aggregate(Aggregation.newAggregation(projectionOperation);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.