spring mongodb - How to provide match condition to check for empty array using spring data mongodb api?

Viewed 4729

how to perform below operation (it is the actual mongo query) using MatchOperation in Spring data mongodb ?

$match: { "docs": { $ne: [] } }

here docs is an array field and want to check that it is not empty.

1 Answers

I also had a similar problem, but I solved is as below.

MatchOperation mathOpertaion = match(Criteria.where("docs") .elemMatch(new Criteria().exists(true)));

Related