Morphia query example : exists() and doesNotExist()

Morphia query example : exists() and doesNotExist()

Morphia does not save empty fields by default. So when an entity attribute is null, the default behavior is to ignore it and not store it on the server side. The exists() method of the fluent Query API allows us to test if a field exists in the mongoDB document while doesNotExist() tests the exact opposite. They both correspont to the $exists mongoDB query operator.

exists() and doesNotExist() query example :

console output :

References

Morphia documentation wiki @ gtihub.com

Morphia Query official documentation

MongoDB $exists documentation

 

Leave a Reply

Your email address will not be published. Required fields are marked *