Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return false for empty list #511

Merged
merged 1 commit into from
May 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/mango/src/mango_selector.erl
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ match({[{<<"$elemMatch">>, _Arg}]}, _Value, _Cmp) ->

% Matches when all elements in values match the
% sub-selector Arg.
match({[{<<"$allMatch">>, Arg}]}, Values, Cmp) when is_list(Values) ->
match({[{<<"$allMatch">>, Arg}]}, Values, Cmp) when is_list(Values), length(Values) > 0 ->
try
lists:foreach(fun(V) ->
case match(Arg, V, Cmp) of
Expand Down
18 changes: 15 additions & 3 deletions src/mango/test/03-operator-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def test_all(self):
"manager": True,
"favorites": {"$all": ["Lisp", "Python"]}
})
print docs
assert len(docs) == 4
assert docs[0]["user_id"] == 2
assert docs[1]["user_id"] == 12
Expand Down Expand Up @@ -59,7 +58,6 @@ def test_elem_match(self):
"bam": True
}}
})
print docs
assert len(docs) == 1
assert docs[0]["user_id"] == "b"

Expand Down Expand Up @@ -94,14 +92,28 @@ def test_all_match(self):
]
self.db.save_docs(amdocs, w=3)
docs = self.db.find({
"_id": {"$gt": None},
"bang": {"$allMatch": {
"foo": {"$mod": [2,1]},
"bar": {"$mod": [2,0]}
}}
})
assert len(docs) == 1
assert docs[0]["user_id"] == "a"

def test_empty_all_match(self):
amdocs = [
{
"bad_doc": "a",
"emptybang": []
}
]
self.db.save_docs(amdocs, w=3)
docs = self.db.find({
"emptybang": {"$allMatch": {
"foo": {"$eq": 2}
}}
})
assert len(docs) == 0

def test_in_operator_array(self):
docs = self.db.find({
Expand Down