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

Fix incorrect indexable_fields for $in #752

Merged
merged 1 commit into from Aug 15, 2017
Jump to file or symbol
Failed to load files and symbols.
+12 −8
Diff settings

Always

Just for now

@@ -307,7 +307,7 @@ indexable_fields(Fields, {op_or, [{op_field, Field0},
{op_field, {[Name | _], _}} = Field1]}) ->
case lists:member(<<"[]">>, Name) of
true ->
indexable_fields(Fields, Field1);
indexable_fields(Fields, {op_field, Field0});
false ->
Fields1 = indexable_fields(Fields, {op_field, Field0}),
indexable_fields(Fields1, Field1)
@@ -64,6 +64,16 @@ def test_in_with_array(self):
docs = self.db.find({"favorites": {"$in": vals}})
assert len(docs) == 10
def test_in_with_array_not_explicit(self):
agelist = [22, 51]
statelist = ["New Hampshire"]
docs = self.db.find({"age": {"$in": agelist}})
docs2 = self.db.find({"location.state": {"$in": statelist}})
docs3 = self.db.find({"age": {"$in": statelist}})
assert len(docs) == 2
assert len(docs2) == 1
assert len(docs3) == 0
# This should also throw an error because we only indexed
# favorites.[] of type string. For the following query to work, the
# user has to index favorites.[] of type number, and also
@@ -75,16 +85,10 @@ def test_in_different_types(self):
except Exception, e:
assert e.response.status_code == 400
# This test differs from the situation where we index everything.
# When we index everything the actual number of docs that gets
# returned is 5. That's because of the special situation where we
# have an array of an array, i.e: [["Lisp"]], because we're indexing
# specifically favorites.[] of type string. So it does not count
# the example and we only get 4 back.
def test_nin_with_array(self):
vals = ["Lisp", "Python"]
docs = self.db.find({"favorites": {"$nin": vals}})
assert len(docs) == 4
assert len(docs) == 5
def test_missing(self):
self.db.find({"location.state": "Nevada"})
ProTip! Use n and p to navigate between commits in a pull request.