-
Type: Improvement
-
Resolution: Fixed
-
Priority: Minor - P4
-
Affects Version/s: None
-
Component/s: None
-
None
-
Fully Compatible
Mongoid has code that wishes to know if a matching document is present in the database, for example in the uniqueness validator:
add_error(document, attribute, value) if criteria.count > 1
Usage of count is inefficient, this should use either any? or exists? depending on whether documents that only exist in the application need to be considered. In case of the uniqueness validator, exists? should be the correct method.
The differences are described in https://www.mongodb.com/docs/mongoid/master/reference/associations/#any and https://www.mongodb.com/docs/mongoid/master/reference/associations/#exists.