0

I have a document with an array. I want to delete the document if array exists and size is of 0.

I came up with this mongodb query(something similar)

document.remove({ comments: { $exists: true, $size: 0 } })

please help me in converting this mongodb query to spring-data-mongodb or suggest me if there is any better solution for this.

1 Answer 1

1

Assuming you have a Document class.

mongoTemplate.remove(new Query(Criteria.where("comments").exists(true).size(0)), Document.class);
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.