Mongo isNull check and null values
See original GitHub issueHello,
I am using Spring Boot with QueryDSL & MongoDB using querydsl-mongodb
version 3.7.4. I have a MongoRepository and am using a QueryDSL Predicate to check if a field contains a null
value like:
repository.findAll(QPerson.person.personId.isNull())
However, this isn’t retrieving results where the value of the field is null
as expected.
Looking at the code for MongodbSerializer, it appears the isNull
operation is translated to an $exists
check in MongoDB which checks if the property exists. Instead, I need to check if the value of the field is null
, which was what I was expecting isNull
to do.
Is there a way to check if a field (that exists) has a null
value using QueryDSL Predicates & MongoDB?
Thank you!
Issue Analytics
- State:
- Created 6 years ago
- Reactions:7
- Comments:9 (2 by maintainers)
Top Results From Across the Web
Query for Null or Missing Fields — MongoDB Manual
The { item : null } query matches documents that either contain the item field whose value is null or that do not...
Read more >MongoDB: How to query for records where field is null or not ...
Type Check · 1. If you want to pick records where sent_at exists and has the value null · 2. If you want...
Read more >MongoDB query with null - w3resource
Description. In this page, we are going to discuss how null value in mongodb documents can be fetched using $type, $exists operators.
Read more >How to Query For Is Not Null in MongoDB? - CodeForGeek
To query for is not null value, we can use the $ne operator as well as the $eq operator and specify the desired...
Read more >How do I check whether a field contains null value in MongoDB?
How do I check whether a field contains null value in MongoDB? - You can use $type operator to check whether a filed...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Found a workaround: `public class NullConstant implements Constant<Object> {
}`
and use it:
qEntity.field.eq(NullConstant.NULL_CONSTANT)
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.