MongoDb: How do I do { 'someField' : null }?

26 views
Skip to first unread message

Joachim Durchholz

unread,
Nov 13, 2022, 5:16:21 AM11/13/22
to Querydsl
Hi all,

I'm trying to translate the MongoDB condition { 'someField' : null } to a QueryDSL Predicate and can't find how to do it. (Note for those that come from the SQL perspective: in MongoDb, this predicate holds if the field is either missing or exists with a value of null.)

I tried QEntity.entity.someField.isNull(), but that translates to {"someField": {"$exists": false}}, which gives a different result if the field exists and has a value of null.

I suspect that's a bug in QueryDsl's MongoDb support. I therefore tried QEntity.entity.someField.eq(somehow-provide-null-as-constant) but all variations of somehow-provide-null-as-constant would give me either a compiler error or a ClassCastException.

So, what should I do?

Regards,
Jo
Reply all
Reply to author
Forward
0 new messages