Writing a MongoDB regex query in Spring with a field that can be null.
I want to query documents by name and phone:
Query(value = "{ {'name' : {$regex:?0,$options:'i'}},
{'phone' : {$regex:?1,$options:'i'}} }")
Document findByFullNameOrPhone(String fullName, String phone);
The value I'm passing through the query for phone is ".*" in an attempt to match everything.
It works but the problem is phone is a field that can be null. If the document has no phone value it's not included in the query result. Is it possible to use this query to find all documents in the database, even if the document does not have a value for phone?