Fix $nin operator
This fixes $nin when the field is an array.
BugzID:44528
diff --git a/src/mango_selector.erl b/src/mango_selector.erl
index 21c55ae..c6004cd 100644
--- a/src/mango_selector.erl
+++ b/src/mango_selector.erl
@@ -471,6 +471,8 @@
Pred = fun(Arg) -> Cmp(Value, Arg) == 0 end,
lists:any(Pred, Args);
+match({[{<<"$nin">>, Args}]}, Values, Cmp) when is_list(Values)->
+ not match({[{<<"$in">>, Args}]}, Values, Cmp);
match({[{<<"$nin">>, Args}]}, Value, Cmp) ->
Pred = fun(Arg) -> Cmp(Value, Arg) /= 0 end,
lists:all(Pred, Args);
diff --git a/test/03-operator-test.py b/test/03-operator-test.py
index d8a7c29..50d5bd2 100644
--- a/test/03-operator-test.py
+++ b/test/03-operator-test.py
@@ -72,6 +72,17 @@
assert docs[0]["user_id"] == 2
assert docs[1]["user_id"] == 12
+ def test_nin_operator_array(self):
+ docs = self.db.find({
+ "manager": True,
+ "favorites": {"$nin": ["Erlang", "Python"]}
+ })
+ assert len(docs) == 4
+ for doc in docs:
+ if isinstance(doc["favorites"], list):
+ assert "Erlang" not in doc["favorites"]
+ assert "Python" not in doc["favorites"]
+
def test_regex(self):
docs = self.db.find({
"age": {"$gt": 40},