-
Type: Improvement
-
Resolution: Works as Designed
-
Priority: Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
Currently this happens:
Customer.where({"$or"=>[]})
#=> Mongo::Error::OperationFailure: [2:BadValue]: $and/$or/$nor must be a nonempty array (on 127.0.0.1:27017, modern retry, attempt 1)
This is not very user friendly. Here is a very simple example which indicates how this makes application code messy:
# given some dynamic criteria or_criteria = [] or_criteria << {cond1: :foo} if x or_criteria << {cond2: :bar} if y # I end up writing these 5 lines... if criteria.present? Customer.where({"$or"=>or_criteria}) else Customer.none end # ...I'd like to do just one line: Customer.where({"$or"=>or_criteria})
We can consider the following:
- empty $and --> returns none
- empty $or --> returns none, unless chaining then its ignored
- empty $nor --> ignored
This ticket is similar to MONGOID-5030
- is related to
-
MONGOID-5282 Lift single-branch $or conditions to top level
- Backlog