Marco C
Marco C

Reputation: 3213

Spring MongoDB Criteria To Check Inside A List Or Map

How can I check if a String is inside:

Set<String> obAccountIDs = new HashSet<String>();

in my User model?

Is the in Criteria method the right approach to use?

Spring Mongo Query Doc

Thanks

Upvotes: 1

Views: 5172

Answers (2)

Neil Lunn
Neil Lunn

Reputation: 151102

Or better to use the $nin operator equivalent:

Criteria.where("obAccountIDs").nin(IDs);

Also noting that $not is a "field specific" operator that is actually only applying to the operator expression and producing the negative. You would not be able to use that "across documents". So $nin is the better action in both cases, apart from requiring less typing.

Upvotes: 3

Marco C
Marco C

Reputation: 3213

Yes, it is.

Criteria.where("obAccountIDs").not().in(IDs);

Upvotes: 0

Related Questions