summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorHana Pearlman <hana.pearlman@mongodb.com>2022-11-22 16:25:42 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-11-22 17:02:03 +0000
commitb9c1d756a2132c2d6fdb1d5892c7f5e03a425cc7 (patch)
tree21461449beb9524f17d95d95312487975d5b3453 /jstests
parent75156fdc78e15594145d89d6f362d401f7dc879f (diff)
downloadmongo-b9c1d756a2132c2d6fdb1d5892c7f5e03a425cc7.tar.gz
SERVER-62328: Add golden jstests for and/or match expressions
Diffstat (limited to 'jstests')
-rw-r--r--jstests/query_golden/expected_output/match_with_and_or691
-rw-r--r--jstests/query_golden/match_with_and_or.js109
2 files changed, 800 insertions, 0 deletions
diff --git a/jstests/query_golden/expected_output/match_with_and_or b/jstests/query_golden/expected_output/match_with_and_or
new file mode 100644
index 00000000000..2aa48eab3a5
--- /dev/null
+++ b/jstests/query_golden/expected_output/match_with_and_or
@@ -0,0 +1,691 @@
+
+
+[jsTest] ----
+[jsTest] Resetting collection. Inserting docs:
+[jsTest] ----
+
+{ "_id" : 0, "x" : 2 }
+{ "_id" : 1, "a" : 1, "x" : 2 }
+{ "_id" : 10, "a" : [ { "b" : [ 1, 2 ], "x" : 1 }, { "x" : 2 } ], "x" : 3 }
+{ "_id" : 11, "a" : [ { "b" : { "d" : [ 1, 2, 3 ] }, "x" : 1 }, { "x" : 2 } ], "x" : 3 }
+{ "_id" : 12, "a" : { "b" : { "c" : 1, "x" : 1 }, "x" : 1 }, "x" : 1 }
+{ "_id" : 13, "a" : [ 1, 2, { "b" : [ 2, { "c" : 1 }, { "c" : 2 }, { "x" : 1 } ] } ], "x" : 2 }
+{ "_id" : 14, "a" : [ 1, 2, { "b" : 1 }, { "b" : { "c" : 1 } }, { "b" : { "c" : 2 } }, { "x" : 1 }, { "x" : { "y" : 1 } } ], "x" : 2 }
+{ "_id" : 15, "a" : [ { "b" : [ { "c" : [ 1, 2 ] } ] } ] }
+{ "_id" : 16, "a" : [ [ 1, { "b" : [ 1, 2, { "c" : 1 }, { "c" : 2 } ] } ] ] }
+{ "_id" : 2, "a" : { "c" : 1 } }
+{ "_id" : 3, "a" : [ 1 ], "x" : 1 }
+{ "_id" : 4, "a" : [ 1, 2, 3, "1" ] }
+{ "_id" : 5, "a" : { "b" : 1, "x" : 1 }, "x" : 2 }
+{ "_id" : 6, "a" : { "b" : [ 1, 2 ], "x" : 2 }, "x" : 3 }
+{ "_id" : 7, "a" : { "b" : [ 2, 3 ], "x" : 3 }, "x" : 4 }
+{ "_id" : 8, "a" : [ { "b" : 1, "x" : 1 }, { "x" : 2 } ], "x" : 3 }
+{ "_id" : 9, "a" : [ 1, 2, { "b" : 1 }, { "b" : 2 } ], "x" : 1 }
+Collection count: 17
+
+[jsTest] ----
+[jsTest] Query: [ { "$match" : { "$and" : [ { "a" : 1 } ] } } ]
+[jsTest] ----
+
+{ "_id" : 1, "a" : 1, "x" : 2 }
+{ "_id" : 13, "a" : [ 1, 2, { "b" : [ 2, { "c" : 1 }, { "c" : 2 }, { "x" : 1 } ] } ], "x" : 2 }
+{ "_id" : 14, "a" : [ 1, 2, { "b" : 1 }, { "b" : { "c" : 1 } }, { "b" : { "c" : 2 } }, { "x" : 1 }, { "x" : { "y" : 1 } } ], "x" : 2 }
+{ "_id" : 3, "a" : [ 1 ], "x" : 1 }
+{ "_id" : 4, "a" : [ 1, 2, 3, "1" ] }
+{ "_id" : 9, "a" : [ 1, 2, { "b" : 1 }, { "b" : 2 } ], "x" : 1 }
+
+
+[jsTest] ----
+[jsTest] Query: [ { "$match" : { "$and" : [ { "a" : { "$lt" : 20 } } ] } } ]
+[jsTest] ----
+
+{ "_id" : 1, "a" : 1, "x" : 2 }
+{ "_id" : 13, "a" : [ 1, 2, { "b" : [ 2, { "c" : 1 }, { "c" : 2 }, { "x" : 1 } ] } ], "x" : 2 }
+{ "_id" : 14, "a" : [ 1, 2, { "b" : 1 }, { "b" : { "c" : 1 } }, { "b" : { "c" : 2 } }, { "x" : 1 }, { "x" : { "y" : 1 } } ], "x" : 2 }
+{ "_id" : 3, "a" : [ 1 ], "x" : 1 }
+{ "_id" : 4, "a" : [ 1, 2, 3, "1" ] }
+{ "_id" : 9, "a" : [ 1, 2, { "b" : 1 }, { "b" : 2 } ], "x" : 1 }
+
+
+[jsTest] ----
+[jsTest] Query: [ { "$match" : { "$and" : [ { "a" : { "$lt" : 20, "$gt" : 0 } } ] } } ]
+[jsTest] ----
+
+{ "_id" : 1, "a" : 1, "x" : 2 }
+{ "_id" : 13, "a" : [ 1, 2, { "b" : [ 2, { "c" : 1 }, { "c" : 2 }, { "x" : 1 } ] } ], "x" : 2 }
+{ "_id" : 14, "a" : [ 1, 2, { "b" : 1 }, { "b" : { "c" : 1 } }, { "b" : { "c" : 2 } }, { "x" : 1 }, { "x" : { "y" : 1 } } ], "x" : 2 }
+{ "_id" : 3, "a" : [ 1 ], "x" : 1 }
+{ "_id" : 4, "a" : [ 1, 2, 3, "1" ] }
+{ "_id" : 9, "a" : [ 1, 2, { "b" : 1 }, { "b" : 2 } ], "x" : 1 }
+
+
+[jsTest] ----
+[jsTest] Query: [ { "$match" : { "$and" : [ { "a" : 1 }, { "a" : 2 } ] } } ]
+[jsTest] ----
+
+{ "_id" : 13, "a" : [ 1, 2, { "b" : [ 2, { "c" : 1 }, { "c" : 2 }, { "x" : 1 } ] } ], "x" : 2 }
+{ "_id" : 14, "a" : [ 1, 2, { "b" : 1 }, { "b" : { "c" : 1 } }, { "b" : { "c" : 2 } }, { "x" : 1 }, { "x" : { "y" : 1 } } ], "x" : 2 }
+{ "_id" : 4, "a" : [ 1, 2, 3, "1" ] }
+{ "_id" : 9, "a" : [ 1, 2, { "b" : 1 }, { "b" : 2 } ], "x" : 1 }
+
+
+[jsTest] ----
+[jsTest] Query: [ { "$match" : { "$and" : [ { "a" : 1 }, { "a" : 1 } ] } } ]
+[jsTest] ----
+
+{ "_id" : 1, "a" : 1, "x" : 2 }
+{ "_id" : 13, "a" : [ 1, 2, { "b" : [ 2, { "c" : 1 }, { "c" : 2 }, { "x" : 1 } ] } ], "x" : 2 }
+{ "_id" : 14, "a" : [ 1, 2, { "b" : 1 }, { "b" : { "c" : 1 } }, { "b" : { "c" : 2 } }, { "x" : 1 }, { "x" : { "y" : 1 } } ], "x" : 2 }
+{ "_id" : 3, "a" : [ 1 ], "x" : 1 }
+{ "_id" : 4, "a" : [ 1, 2, 3, "1" ] }
+{ "_id" : 9, "a" : [ 1, 2, { "b" : 1 }, { "b" : 2 } ], "x" : 1 }
+
+
+[jsTest] ----
+[jsTest] Query: [ { "$match" : { "$and" : [ { "a" : { "$in" : [ 1, 3 ] } }, { "a" : { "$in" : [ 2, 4 ] } } ] } } ]
+[jsTest] ----
+
+{ "_id" : 13, "a" : [ 1, 2, { "b" : [ 2, { "c" : 1 }, { "c" : 2 }, { "x" : 1 } ] } ], "x" : 2 }
+{ "_id" : 14, "a" : [ 1, 2, { "b" : 1 }, { "b" : { "c" : 1 } }, { "b" : { "c" : 2 } }, { "x" : 1 }, { "x" : { "y" : 1 } } ], "x" : 2 }
+{ "_id" : 4, "a" : [ 1, 2, 3, "1" ] }
+{ "_id" : 9, "a" : [ 1, 2, { "b" : 1 }, { "b" : 2 } ], "x" : 1 }
+
+
+[jsTest] ----
+[jsTest] Query: [ { "$match" : { "$and" : [ { "a.b" : 1 }, { "a.b" : 2 } ] } } ]
+[jsTest] ----
+
+{ "_id" : 10, "a" : [ { "b" : [ 1, 2 ], "x" : 1 }, { "x" : 2 } ], "x" : 3 }
+{ "_id" : 6, "a" : { "b" : [ 1, 2 ], "x" : 2 }, "x" : 3 }
+{ "_id" : 9, "a" : [ 1, 2, { "b" : 1 }, { "b" : 2 } ], "x" : 1 }
+
+
+[jsTest] ----
+[jsTest] Query: [ { "$match" : { "$and" : [ { "a" : { "$lt" : 20 } }, { "a" : { "$gt" : 0 } } ] } } ]
+[jsTest] ----
+
+{ "_id" : 1, "a" : 1, "x" : 2 }
+{ "_id" : 13, "a" : [ 1, 2, { "b" : [ 2, { "c" : 1 }, { "c" : 2 }, { "x" : 1 } ] } ], "x" : 2 }
+{ "_id" : 14, "a" : [ 1, 2, { "b" : 1 }, { "b" : { "c" : 1 } }, { "b" : { "c" : 2 } }, { "x" : 1 }, { "x" : { "y" : 1 } } ], "x" : 2 }
+{ "_id" : 3, "a" : [ 1 ], "x" : 1 }
+{ "_id" : 4, "a" : [ 1, 2, 3, "1" ] }
+{ "_id" : 9, "a" : [ 1, 2, { "b" : 1 }, { "b" : 2 } ], "x" : 1 }
+
+
+[jsTest] ----
+[jsTest] Query: [ { "$match" : { "$and" : [ { "a" : { "$gt" : 0 } }, { "a" : { "$gte" : 0 } } ] } } ]
+[jsTest] ----
+
+{ "_id" : 1, "a" : 1, "x" : 2 }
+{ "_id" : 13, "a" : [ 1, 2, { "b" : [ 2, { "c" : 1 }, { "c" : 2 }, { "x" : 1 } ] } ], "x" : 2 }
+{ "_id" : 14, "a" : [ 1, 2, { "b" : 1 }, { "b" : { "c" : 1 } }, { "b" : { "c" : 2 } }, { "x" : 1 }, { "x" : { "y" : 1 } } ], "x" : 2 }
+{ "_id" : 3, "a" : [ 1 ], "x" : 1 }
+{ "_id" : 4, "a" : [ 1, 2, 3, "1" ] }
+{ "_id" : 9, "a" : [ 1, 2, { "b" : 1 }, { "b" : 2 } ], "x" : 1 }
+
+
+[jsTest] ----
+[jsTest] Query: [ { "$match" : { "$and" : [ { "a" : { "$lte" : 1 } }, { "a" : { "$gte" : 2 } } ] } } ]
+[jsTest] ----
+
+{ "_id" : 13, "a" : [ 1, 2, { "b" : [ 2, { "c" : 1 }, { "c" : 2 }, { "x" : 1 } ] } ], "x" : 2 }
+{ "_id" : 14, "a" : [ 1, 2, { "b" : 1 }, { "b" : { "c" : 1 } }, { "b" : { "c" : 2 } }, { "x" : 1 }, { "x" : { "y" : 1 } } ], "x" : 2 }
+{ "_id" : 4, "a" : [ 1, 2, 3, "1" ] }
+{ "_id" : 9, "a" : [ 1, 2, { "b" : 1 }, { "b" : 2 } ], "x" : 1 }
+
+
+[jsTest] ----
+[jsTest] Query: [ { "$match" : { "$and" : [ { "a" : { "$lt" : 20, "$gt" : 0 } }, { "a" : { "$lt" : 10, "$gt" : -5 } } ] } } ]
+[jsTest] ----
+
+{ "_id" : 1, "a" : 1, "x" : 2 }
+{ "_id" : 13, "a" : [ 1, 2, { "b" : [ 2, { "c" : 1 }, { "c" : 2 }, { "x" : 1 } ] } ], "x" : 2 }
+{ "_id" : 14, "a" : [ 1, 2, { "b" : 1 }, { "b" : { "c" : 1 } }, { "b" : { "c" : 2 } }, { "x" : 1 }, { "x" : { "y" : 1 } } ], "x" : 2 }
+{ "_id" : 3, "a" : [ 1 ], "x" : 1 }
+{ "_id" : 4, "a" : [ 1, 2, 3, "1" ] }
+{ "_id" : 9, "a" : [ 1, 2, { "b" : 1 }, { "b" : 2 } ], "x" : 1 }
+
+
+[jsTest] ----
+[jsTest] Query: [ { "$match" : { "$and" : [ { "a" : { "$gt" : 1 } }, { "a" : { "$lt" : "2" } } ] } } ]
+[jsTest] ----
+
+{ "_id" : 4, "a" : [ 1, 2, 3, "1" ] }
+
+
+[jsTest] ----
+[jsTest] Query: [ { "$match" : { "$and" : [ { "a" : null }, { "a" : { "$exists" : false } } ] } } ]
+[jsTest] ----
+
+{ "_id" : 0, "x" : 2 }
+
+
+[jsTest] ----
+[jsTest] Query: [ { "$match" : { "$and" : [ { "a" : { "$in" : [ 1, 2, 3 ] } }, { "a" : { "$in" : [ 3, 4, 5 ] } } ] } } ]
+[jsTest] ----
+
+{ "_id" : 4, "a" : [ 1, 2, 3, "1" ] }
+
+
+[jsTest] ----
+[jsTest] Query: [ { "$match" : { "$and" : [ { "a" : 1 }, { "a" : { "$not" : { "$eq" : 1 } } } ] } } ]
+[jsTest] ----
+
+
+
+
+[jsTest] ----
+[jsTest] Query: [ { "$match" : { "$and" : [ { "a" : { "$exists" : false } }, { "a" : { "$exists" : true } } ] } } ]
+[jsTest] ----
+
+
+
+
+[jsTest] ----
+[jsTest] Query: [ { "$match" : { "$and" : [ { "a.b" : { "$exists" : false } }, { "a.b" : { "$exists" : true } } ] } } ]
+[jsTest] ----
+
+
+
+
+[jsTest] ----
+[jsTest] Query: [ { "$match" : { "$and" : [ { "a.b" : 1 }, { "a.x" : 1 } ] } } ]
+[jsTest] ----
+
+{ "_id" : 10, "a" : [ { "b" : [ 1, 2 ], "x" : 1 }, { "x" : 2 } ], "x" : 3 }
+{ "_id" : 14, "a" : [ 1, 2, { "b" : 1 }, { "b" : { "c" : 1 } }, { "b" : { "c" : 2 } }, { "x" : 1 }, { "x" : { "y" : 1 } } ], "x" : 2 }
+{ "_id" : 5, "a" : { "b" : 1, "x" : 1 }, "x" : 2 }
+{ "_id" : 8, "a" : [ { "b" : 1, "x" : 1 }, { "x" : 2 } ], "x" : 3 }
+
+
+[jsTest] ----
+[jsTest] Query: [ { "$match" : { "$and" : [ { "a.b.c" : 1 }, { "a.x.y" : 1 } ] } } ]
+[jsTest] ----
+
+{ "_id" : 14, "a" : [ 1, 2, { "b" : 1 }, { "b" : { "c" : 1 } }, { "b" : { "c" : 2 } }, { "x" : 1 }, { "x" : { "y" : 1 } } ], "x" : 2 }
+
+
+[jsTest] ----
+[jsTest] Query: [ { "$match" : { "$and" : [ { "a.b.c" : 1 }, { "a.b.x" : 1 } ] } } ]
+[jsTest] ----
+
+{ "_id" : 12, "a" : { "b" : { "c" : 1, "x" : 1 }, "x" : 1 }, "x" : 1 }
+{ "_id" : 13, "a" : [ 1, 2, { "b" : [ 2, { "c" : 1 }, { "c" : 2 }, { "x" : 1 } ] } ], "x" : 2 }
+
+
+[jsTest] ----
+[jsTest] Query: [ { "$match" : { "$and" : [ { "a.b" : 1 }, { "a.b.c" : 2 } ] } } ]
+[jsTest] ----
+
+{ "_id" : 14, "a" : [ 1, 2, { "b" : 1 }, { "b" : { "c" : 1 } }, { "b" : { "c" : 2 } }, { "x" : 1 }, { "x" : { "y" : 1 } } ], "x" : 2 }
+
+
+[jsTest] ----
+[jsTest] Query: [ { "$match" : { "$and" : [ { "a" : 1 }, { "x" : 2 } ] } } ]
+[jsTest] ----
+
+{ "_id" : 1, "a" : 1, "x" : 2 }
+{ "_id" : 13, "a" : [ 1, 2, { "b" : [ 2, { "c" : 1 }, { "c" : 2 }, { "x" : 1 } ] } ], "x" : 2 }
+{ "_id" : 14, "a" : [ 1, 2, { "b" : 1 }, { "b" : { "c" : 1 } }, { "b" : { "c" : 2 } }, { "x" : 1 }, { "x" : { "y" : 1 } } ], "x" : 2 }
+
+
+[jsTest] ----
+[jsTest] Query: [ { "$match" : { "$and" : [ { "a" : 1 }, { "a" : 2 }, { "a.b" : 1 }, { "x" : 2 } ] } } ]
+[jsTest] ----
+
+{ "_id" : 14, "a" : [ 1, 2, { "b" : 1 }, { "b" : { "c" : 1 } }, { "b" : { "c" : 2 } }, { "x" : 1 }, { "x" : { "y" : 1 } } ], "x" : 2 }
+
+
+[jsTest] ----
+[jsTest] Query: [ { "$match" : { "$and" : [ { "_id" : { "$exists" : true } }, { "a" : 1 } ] } } ]
+[jsTest] ----
+
+{ "_id" : 1, "a" : 1, "x" : 2 }
+{ "_id" : 13, "a" : [ 1, 2, { "b" : [ 2, { "c" : 1 }, { "c" : 2 }, { "x" : 1 } ] } ], "x" : 2 }
+{ "_id" : 14, "a" : [ 1, 2, { "b" : 1 }, { "b" : { "c" : 1 } }, { "b" : { "c" : 2 } }, { "x" : 1 }, { "x" : { "y" : 1 } } ], "x" : 2 }
+{ "_id" : 3, "a" : [ 1 ], "x" : 1 }
+{ "_id" : 4, "a" : [ 1, 2, 3, "1" ] }
+{ "_id" : 9, "a" : [ 1, 2, { "b" : 1 }, { "b" : 2 } ], "x" : 1 }
+
+
+[jsTest] ----
+[jsTest] Query: [ { "$match" : { "$and" : [ { }, { "a" : 1 } ] } } ]
+[jsTest] ----
+
+{ "_id" : 1, "a" : 1, "x" : 2 }
+{ "_id" : 13, "a" : [ 1, 2, { "b" : [ 2, { "c" : 1 }, { "c" : 2 }, { "x" : 1 } ] } ], "x" : 2 }
+{ "_id" : 14, "a" : [ 1, 2, { "b" : 1 }, { "b" : { "c" : 1 } }, { "b" : { "c" : 2 } }, { "x" : 1 }, { "x" : { "y" : 1 } } ], "x" : 2 }
+{ "_id" : 3, "a" : [ 1 ], "x" : 1 }
+{ "_id" : 4, "a" : [ 1, 2, 3, "1" ] }
+{ "_id" : 9, "a" : [ 1, 2, { "b" : 1 }, { "b" : 2 } ], "x" : 1 }
+
+
+[jsTest] ----
+[jsTest] Query: [ { "$match" : { "$and" : [ { "_id" : { "$exists" : false } }, { "a" : 1 } ] } } ]
+[jsTest] ----
+
+
+
+
+[jsTest] ----
+[jsTest] Query: [ { "$match" : { "$and" : [ { "$or" : [ { "a.b" : 1 }, { "a.b" : 2 } ] }, { "$and" : [ { "x" : { "$exists" : true } }, { "a" : { "$exists" : true } } ] } ] } } ]
+[jsTest] ----
+
+{ "_id" : 10, "a" : [ { "b" : [ 1, 2 ], "x" : 1 }, { "x" : 2 } ], "x" : 3 }
+{ "_id" : 13, "a" : [ 1, 2, { "b" : [ 2, { "c" : 1 }, { "c" : 2 }, { "x" : 1 } ] } ], "x" : 2 }
+{ "_id" : 14, "a" : [ 1, 2, { "b" : 1 }, { "b" : { "c" : 1 } }, { "b" : { "c" : 2 } }, { "x" : 1 }, { "x" : { "y" : 1 } } ], "x" : 2 }
+{ "_id" : 5, "a" : { "b" : 1, "x" : 1 }, "x" : 2 }
+{ "_id" : 6, "a" : { "b" : [ 1, 2 ], "x" : 2 }, "x" : 3 }
+{ "_id" : 7, "a" : { "b" : [ 2, 3 ], "x" : 3 }, "x" : 4 }
+{ "_id" : 8, "a" : [ { "b" : 1, "x" : 1 }, { "x" : 2 } ], "x" : 3 }
+{ "_id" : 9, "a" : [ 1, 2, { "b" : 1 }, { "b" : 2 } ], "x" : 1 }
+
+
+[jsTest] ----
+[jsTest] Query: [ { "$match" : { "$and" : [ { "$or" : [ { "$or" : [ { "a.b" : 1 }, { "a.b" : 2 } ] }, { "$and" : [ { "x" : { "$exists" : true } }, { "a.b.c" : { "$exists" : true } } ] } ] }, { "$and" : [ { "$or" : [ { "a.b.c" : 1 }, { "a.b.c" : 2 } ] }, { "$and" : [ { "a" : 1 }, { "a" : 2 } ] } ] } ] } } ]
+[jsTest] ----
+
+{ "_id" : 13, "a" : [ 1, 2, { "b" : [ 2, { "c" : 1 }, { "c" : 2 }, { "x" : 1 } ] } ], "x" : 2 }
+{ "_id" : 14, "a" : [ 1, 2, { "b" : 1 }, { "b" : { "c" : 1 } }, { "b" : { "c" : 2 } }, { "x" : 1 }, { "x" : { "y" : 1 } } ], "x" : 2 }
+
+
+[jsTest] ----
+[jsTest] Query: [ { "$match" : { "$or" : [ { "a" : 1 } ] } } ]
+[jsTest] ----
+
+{ "_id" : 1, "a" : 1, "x" : 2 }
+{ "_id" : 13, "a" : [ 1, 2, { "b" : [ 2, { "c" : 1 }, { "c" : 2 }, { "x" : 1 } ] } ], "x" : 2 }
+{ "_id" : 14, "a" : [ 1, 2, { "b" : 1 }, { "b" : { "c" : 1 } }, { "b" : { "c" : 2 } }, { "x" : 1 }, { "x" : { "y" : 1 } } ], "x" : 2 }
+{ "_id" : 3, "a" : [ 1 ], "x" : 1 }
+{ "_id" : 4, "a" : [ 1, 2, 3, "1" ] }
+{ "_id" : 9, "a" : [ 1, 2, { "b" : 1 }, { "b" : 2 } ], "x" : 1 }
+
+
+[jsTest] ----
+[jsTest] Query: [ { "$match" : { "$or" : [ { "a" : { "$lt" : 20 } } ] } } ]
+[jsTest] ----
+
+{ "_id" : 1, "a" : 1, "x" : 2 }
+{ "_id" : 13, "a" : [ 1, 2, { "b" : [ 2, { "c" : 1 }, { "c" : 2 }, { "x" : 1 } ] } ], "x" : 2 }
+{ "_id" : 14, "a" : [ 1, 2, { "b" : 1 }, { "b" : { "c" : 1 } }, { "b" : { "c" : 2 } }, { "x" : 1 }, { "x" : { "y" : 1 } } ], "x" : 2 }
+{ "_id" : 3, "a" : [ 1 ], "x" : 1 }
+{ "_id" : 4, "a" : [ 1, 2, 3, "1" ] }
+{ "_id" : 9, "a" : [ 1, 2, { "b" : 1 }, { "b" : 2 } ], "x" : 1 }
+
+
+[jsTest] ----
+[jsTest] Query: [ { "$match" : { "$or" : [ { "a" : { "$lt" : 20, "$gt" : 0 } } ] } } ]
+[jsTest] ----
+
+{ "_id" : 1, "a" : 1, "x" : 2 }
+{ "_id" : 13, "a" : [ 1, 2, { "b" : [ 2, { "c" : 1 }, { "c" : 2 }, { "x" : 1 } ] } ], "x" : 2 }
+{ "_id" : 14, "a" : [ 1, 2, { "b" : 1 }, { "b" : { "c" : 1 } }, { "b" : { "c" : 2 } }, { "x" : 1 }, { "x" : { "y" : 1 } } ], "x" : 2 }
+{ "_id" : 3, "a" : [ 1 ], "x" : 1 }
+{ "_id" : 4, "a" : [ 1, 2, 3, "1" ] }
+{ "_id" : 9, "a" : [ 1, 2, { "b" : 1 }, { "b" : 2 } ], "x" : 1 }
+
+
+[jsTest] ----
+[jsTest] Query: [ { "$match" : { "$or" : [ { "a" : 1 }, { "a" : 2 } ] } } ]
+[jsTest] ----
+
+{ "_id" : 1, "a" : 1, "x" : 2 }
+{ "_id" : 13, "a" : [ 1, 2, { "b" : [ 2, { "c" : 1 }, { "c" : 2 }, { "x" : 1 } ] } ], "x" : 2 }
+{ "_id" : 14, "a" : [ 1, 2, { "b" : 1 }, { "b" : { "c" : 1 } }, { "b" : { "c" : 2 } }, { "x" : 1 }, { "x" : { "y" : 1 } } ], "x" : 2 }
+{ "_id" : 3, "a" : [ 1 ], "x" : 1 }
+{ "_id" : 4, "a" : [ 1, 2, 3, "1" ] }
+{ "_id" : 9, "a" : [ 1, 2, { "b" : 1 }, { "b" : 2 } ], "x" : 1 }
+
+
+[jsTest] ----
+[jsTest] Query: [ { "$match" : { "$or" : [ { "a" : 1 }, { "a" : 1 } ] } } ]
+[jsTest] ----
+
+{ "_id" : 1, "a" : 1, "x" : 2 }
+{ "_id" : 13, "a" : [ 1, 2, { "b" : [ 2, { "c" : 1 }, { "c" : 2 }, { "x" : 1 } ] } ], "x" : 2 }
+{ "_id" : 14, "a" : [ 1, 2, { "b" : 1 }, { "b" : { "c" : 1 } }, { "b" : { "c" : 2 } }, { "x" : 1 }, { "x" : { "y" : 1 } } ], "x" : 2 }
+{ "_id" : 3, "a" : [ 1 ], "x" : 1 }
+{ "_id" : 4, "a" : [ 1, 2, 3, "1" ] }
+{ "_id" : 9, "a" : [ 1, 2, { "b" : 1 }, { "b" : 2 } ], "x" : 1 }
+
+
+[jsTest] ----
+[jsTest] Query: [ { "$match" : { "$or" : [ { "a" : { "$in" : [ 1, 3 ] } }, { "a" : { "$in" : [ 2, 4 ] } } ] } } ]
+[jsTest] ----
+
+{ "_id" : 1, "a" : 1, "x" : 2 }
+{ "_id" : 13, "a" : [ 1, 2, { "b" : [ 2, { "c" : 1 }, { "c" : 2 }, { "x" : 1 } ] } ], "x" : 2 }
+{ "_id" : 14, "a" : [ 1, 2, { "b" : 1 }, { "b" : { "c" : 1 } }, { "b" : { "c" : 2 } }, { "x" : 1 }, { "x" : { "y" : 1 } } ], "x" : 2 }
+{ "_id" : 3, "a" : [ 1 ], "x" : 1 }
+{ "_id" : 4, "a" : [ 1, 2, 3, "1" ] }
+{ "_id" : 9, "a" : [ 1, 2, { "b" : 1 }, { "b" : 2 } ], "x" : 1 }
+
+
+[jsTest] ----
+[jsTest] Query: [ { "$match" : { "$or" : [ { "a.b" : 1 }, { "a.b" : 2 } ] } } ]
+[jsTest] ----
+
+{ "_id" : 10, "a" : [ { "b" : [ 1, 2 ], "x" : 1 }, { "x" : 2 } ], "x" : 3 }
+{ "_id" : 13, "a" : [ 1, 2, { "b" : [ 2, { "c" : 1 }, { "c" : 2 }, { "x" : 1 } ] } ], "x" : 2 }
+{ "_id" : 14, "a" : [ 1, 2, { "b" : 1 }, { "b" : { "c" : 1 } }, { "b" : { "c" : 2 } }, { "x" : 1 }, { "x" : { "y" : 1 } } ], "x" : 2 }
+{ "_id" : 5, "a" : { "b" : 1, "x" : 1 }, "x" : 2 }
+{ "_id" : 6, "a" : { "b" : [ 1, 2 ], "x" : 2 }, "x" : 3 }
+{ "_id" : 7, "a" : { "b" : [ 2, 3 ], "x" : 3 }, "x" : 4 }
+{ "_id" : 8, "a" : [ { "b" : 1, "x" : 1 }, { "x" : 2 } ], "x" : 3 }
+{ "_id" : 9, "a" : [ 1, 2, { "b" : 1 }, { "b" : 2 } ], "x" : 1 }
+
+
+[jsTest] ----
+[jsTest] Query: [ { "$match" : { "$or" : [ { "a" : { "$lt" : 20 } }, { "a" : { "$gt" : 0 } } ] } } ]
+[jsTest] ----
+
+{ "_id" : 1, "a" : 1, "x" : 2 }
+{ "_id" : 13, "a" : [ 1, 2, { "b" : [ 2, { "c" : 1 }, { "c" : 2 }, { "x" : 1 } ] } ], "x" : 2 }
+{ "_id" : 14, "a" : [ 1, 2, { "b" : 1 }, { "b" : { "c" : 1 } }, { "b" : { "c" : 2 } }, { "x" : 1 }, { "x" : { "y" : 1 } } ], "x" : 2 }
+{ "_id" : 3, "a" : [ 1 ], "x" : 1 }
+{ "_id" : 4, "a" : [ 1, 2, 3, "1" ] }
+{ "_id" : 9, "a" : [ 1, 2, { "b" : 1 }, { "b" : 2 } ], "x" : 1 }
+
+
+[jsTest] ----
+[jsTest] Query: [ { "$match" : { "$or" : [ { "a" : { "$gt" : 0 } }, { "a" : { "$gte" : 0 } } ] } } ]
+[jsTest] ----
+
+{ "_id" : 1, "a" : 1, "x" : 2 }
+{ "_id" : 13, "a" : [ 1, 2, { "b" : [ 2, { "c" : 1 }, { "c" : 2 }, { "x" : 1 } ] } ], "x" : 2 }
+{ "_id" : 14, "a" : [ 1, 2, { "b" : 1 }, { "b" : { "c" : 1 } }, { "b" : { "c" : 2 } }, { "x" : 1 }, { "x" : { "y" : 1 } } ], "x" : 2 }
+{ "_id" : 3, "a" : [ 1 ], "x" : 1 }
+{ "_id" : 4, "a" : [ 1, 2, 3, "1" ] }
+{ "_id" : 9, "a" : [ 1, 2, { "b" : 1 }, { "b" : 2 } ], "x" : 1 }
+
+
+[jsTest] ----
+[jsTest] Query: [ { "$match" : { "$or" : [ { "a" : { "$lte" : 1 } }, { "a" : { "$gte" : 2 } } ] } } ]
+[jsTest] ----
+
+{ "_id" : 1, "a" : 1, "x" : 2 }
+{ "_id" : 13, "a" : [ 1, 2, { "b" : [ 2, { "c" : 1 }, { "c" : 2 }, { "x" : 1 } ] } ], "x" : 2 }
+{ "_id" : 14, "a" : [ 1, 2, { "b" : 1 }, { "b" : { "c" : 1 } }, { "b" : { "c" : 2 } }, { "x" : 1 }, { "x" : { "y" : 1 } } ], "x" : 2 }
+{ "_id" : 3, "a" : [ 1 ], "x" : 1 }
+{ "_id" : 4, "a" : [ 1, 2, 3, "1" ] }
+{ "_id" : 9, "a" : [ 1, 2, { "b" : 1 }, { "b" : 2 } ], "x" : 1 }
+
+
+[jsTest] ----
+[jsTest] Query: [ { "$match" : { "$or" : [ { "a" : { "$lt" : 20, "$gt" : 0 } }, { "a" : { "$lt" : 10, "$gt" : -5 } } ] } } ]
+[jsTest] ----
+
+{ "_id" : 1, "a" : 1, "x" : 2 }
+{ "_id" : 13, "a" : [ 1, 2, { "b" : [ 2, { "c" : 1 }, { "c" : 2 }, { "x" : 1 } ] } ], "x" : 2 }
+{ "_id" : 14, "a" : [ 1, 2, { "b" : 1 }, { "b" : { "c" : 1 } }, { "b" : { "c" : 2 } }, { "x" : 1 }, { "x" : { "y" : 1 } } ], "x" : 2 }
+{ "_id" : 3, "a" : [ 1 ], "x" : 1 }
+{ "_id" : 4, "a" : [ 1, 2, 3, "1" ] }
+{ "_id" : 9, "a" : [ 1, 2, { "b" : 1 }, { "b" : 2 } ], "x" : 1 }
+
+
+[jsTest] ----
+[jsTest] Query: [ { "$match" : { "$or" : [ { "a" : { "$gt" : 1 } }, { "a" : { "$lt" : "2" } } ] } } ]
+[jsTest] ----
+
+{ "_id" : 13, "a" : [ 1, 2, { "b" : [ 2, { "c" : 1 }, { "c" : 2 }, { "x" : 1 } ] } ], "x" : 2 }
+{ "_id" : 14, "a" : [ 1, 2, { "b" : 1 }, { "b" : { "c" : 1 } }, { "b" : { "c" : 2 } }, { "x" : 1 }, { "x" : { "y" : 1 } } ], "x" : 2 }
+{ "_id" : 4, "a" : [ 1, 2, 3, "1" ] }
+{ "_id" : 9, "a" : [ 1, 2, { "b" : 1 }, { "b" : 2 } ], "x" : 1 }
+
+
+[jsTest] ----
+[jsTest] Query: [ { "$match" : { "$or" : [ { "a" : null }, { "a" : { "$exists" : false } } ] } } ]
+[jsTest] ----
+
+{ "_id" : 0, "x" : 2 }
+
+
+[jsTest] ----
+[jsTest] Query: [ { "$match" : { "$or" : [ { "a" : { "$in" : [ 1, 2, 3 ] } }, { "a" : { "$in" : [ 3, 4, 5 ] } } ] } } ]
+[jsTest] ----
+
+{ "_id" : 1, "a" : 1, "x" : 2 }
+{ "_id" : 13, "a" : [ 1, 2, { "b" : [ 2, { "c" : 1 }, { "c" : 2 }, { "x" : 1 } ] } ], "x" : 2 }
+{ "_id" : 14, "a" : [ 1, 2, { "b" : 1 }, { "b" : { "c" : 1 } }, { "b" : { "c" : 2 } }, { "x" : 1 }, { "x" : { "y" : 1 } } ], "x" : 2 }
+{ "_id" : 3, "a" : [ 1 ], "x" : 1 }
+{ "_id" : 4, "a" : [ 1, 2, 3, "1" ] }
+{ "_id" : 9, "a" : [ 1, 2, { "b" : 1 }, { "b" : 2 } ], "x" : 1 }
+
+
+[jsTest] ----
+[jsTest] Query: [ { "$match" : { "$or" : [ { "a" : 1 }, { "a" : { "$not" : { "$eq" : 1 } } } ] } } ]
+[jsTest] ----
+
+{ "_id" : 0, "x" : 2 }
+{ "_id" : 1, "a" : 1, "x" : 2 }
+{ "_id" : 10, "a" : [ { "b" : [ 1, 2 ], "x" : 1 }, { "x" : 2 } ], "x" : 3 }
+{ "_id" : 11, "a" : [ { "b" : { "d" : [ 1, 2, 3 ] }, "x" : 1 }, { "x" : 2 } ], "x" : 3 }
+{ "_id" : 12, "a" : { "b" : { "c" : 1, "x" : 1 }, "x" : 1 }, "x" : 1 }
+{ "_id" : 13, "a" : [ 1, 2, { "b" : [ 2, { "c" : 1 }, { "c" : 2 }, { "x" : 1 } ] } ], "x" : 2 }
+{ "_id" : 14, "a" : [ 1, 2, { "b" : 1 }, { "b" : { "c" : 1 } }, { "b" : { "c" : 2 } }, { "x" : 1 }, { "x" : { "y" : 1 } } ], "x" : 2 }
+{ "_id" : 15, "a" : [ { "b" : [ { "c" : [ 1, 2 ] } ] } ] }
+{ "_id" : 16, "a" : [ [ 1, { "b" : [ 1, 2, { "c" : 1 }, { "c" : 2 } ] } ] ] }
+{ "_id" : 2, "a" : { "c" : 1 } }
+{ "_id" : 3, "a" : [ 1 ], "x" : 1 }
+{ "_id" : 4, "a" : [ 1, 2, 3, "1" ] }
+{ "_id" : 5, "a" : { "b" : 1, "x" : 1 }, "x" : 2 }
+{ "_id" : 6, "a" : { "b" : [ 1, 2 ], "x" : 2 }, "x" : 3 }
+{ "_id" : 7, "a" : { "b" : [ 2, 3 ], "x" : 3 }, "x" : 4 }
+{ "_id" : 8, "a" : [ { "b" : 1, "x" : 1 }, { "x" : 2 } ], "x" : 3 }
+{ "_id" : 9, "a" : [ 1, 2, { "b" : 1 }, { "b" : 2 } ], "x" : 1 }
+
+
+[jsTest] ----
+[jsTest] Query: [ { "$match" : { "$or" : [ { "a" : { "$exists" : false } }, { "a" : { "$exists" : true } } ] } } ]
+[jsTest] ----
+
+{ "_id" : 0, "x" : 2 }
+{ "_id" : 1, "a" : 1, "x" : 2 }
+{ "_id" : 10, "a" : [ { "b" : [ 1, 2 ], "x" : 1 }, { "x" : 2 } ], "x" : 3 }
+{ "_id" : 11, "a" : [ { "b" : { "d" : [ 1, 2, 3 ] }, "x" : 1 }, { "x" : 2 } ], "x" : 3 }
+{ "_id" : 12, "a" : { "b" : { "c" : 1, "x" : 1 }, "x" : 1 }, "x" : 1 }
+{ "_id" : 13, "a" : [ 1, 2, { "b" : [ 2, { "c" : 1 }, { "c" : 2 }, { "x" : 1 } ] } ], "x" : 2 }
+{ "_id" : 14, "a" : [ 1, 2, { "b" : 1 }, { "b" : { "c" : 1 } }, { "b" : { "c" : 2 } }, { "x" : 1 }, { "x" : { "y" : 1 } } ], "x" : 2 }
+{ "_id" : 15, "a" : [ { "b" : [ { "c" : [ 1, 2 ] } ] } ] }
+{ "_id" : 16, "a" : [ [ 1, { "b" : [ 1, 2, { "c" : 1 }, { "c" : 2 } ] } ] ] }
+{ "_id" : 2, "a" : { "c" : 1 } }
+{ "_id" : 3, "a" : [ 1 ], "x" : 1 }
+{ "_id" : 4, "a" : [ 1, 2, 3, "1" ] }
+{ "_id" : 5, "a" : { "b" : 1, "x" : 1 }, "x" : 2 }
+{ "_id" : 6, "a" : { "b" : [ 1, 2 ], "x" : 2 }, "x" : 3 }
+{ "_id" : 7, "a" : { "b" : [ 2, 3 ], "x" : 3 }, "x" : 4 }
+{ "_id" : 8, "a" : [ { "b" : 1, "x" : 1 }, { "x" : 2 } ], "x" : 3 }
+{ "_id" : 9, "a" : [ 1, 2, { "b" : 1 }, { "b" : 2 } ], "x" : 1 }
+
+
+[jsTest] ----
+[jsTest] Query: [ { "$match" : { "$or" : [ { "a.b" : { "$exists" : false } }, { "a.b" : { "$exists" : true } } ] } } ]
+[jsTest] ----
+
+{ "_id" : 0, "x" : 2 }
+{ "_id" : 1, "a" : 1, "x" : 2 }
+{ "_id" : 10, "a" : [ { "b" : [ 1, 2 ], "x" : 1 }, { "x" : 2 } ], "x" : 3 }
+{ "_id" : 11, "a" : [ { "b" : { "d" : [ 1, 2, 3 ] }, "x" : 1 }, { "x" : 2 } ], "x" : 3 }
+{ "_id" : 12, "a" : { "b" : { "c" : 1, "x" : 1 }, "x" : 1 }, "x" : 1 }
+{ "_id" : 13, "a" : [ 1, 2, { "b" : [ 2, { "c" : 1 }, { "c" : 2 }, { "x" : 1 } ] } ], "x" : 2 }
+{ "_id" : 14, "a" : [ 1, 2, { "b" : 1 }, { "b" : { "c" : 1 } }, { "b" : { "c" : 2 } }, { "x" : 1 }, { "x" : { "y" : 1 } } ], "x" : 2 }
+{ "_id" : 15, "a" : [ { "b" : [ { "c" : [ 1, 2 ] } ] } ] }
+{ "_id" : 16, "a" : [ [ 1, { "b" : [ 1, 2, { "c" : 1 }, { "c" : 2 } ] } ] ] }
+{ "_id" : 2, "a" : { "c" : 1 } }
+{ "_id" : 3, "a" : [ 1 ], "x" : 1 }
+{ "_id" : 4, "a" : [ 1, 2, 3, "1" ] }
+{ "_id" : 5, "a" : { "b" : 1, "x" : 1 }, "x" : 2 }
+{ "_id" : 6, "a" : { "b" : [ 1, 2 ], "x" : 2 }, "x" : 3 }
+{ "_id" : 7, "a" : { "b" : [ 2, 3 ], "x" : 3 }, "x" : 4 }
+{ "_id" : 8, "a" : [ { "b" : 1, "x" : 1 }, { "x" : 2 } ], "x" : 3 }
+{ "_id" : 9, "a" : [ 1, 2, { "b" : 1 }, { "b" : 2 } ], "x" : 1 }
+
+
+[jsTest] ----
+[jsTest] Query: [ { "$match" : { "$or" : [ { "a.b" : 1 }, { "a.x" : 1 } ] } } ]
+[jsTest] ----
+
+{ "_id" : 10, "a" : [ { "b" : [ 1, 2 ], "x" : 1 }, { "x" : 2 } ], "x" : 3 }
+{ "_id" : 11, "a" : [ { "b" : { "d" : [ 1, 2, 3 ] }, "x" : 1 }, { "x" : 2 } ], "x" : 3 }
+{ "_id" : 12, "a" : { "b" : { "c" : 1, "x" : 1 }, "x" : 1 }, "x" : 1 }
+{ "_id" : 14, "a" : [ 1, 2, { "b" : 1 }, { "b" : { "c" : 1 } }, { "b" : { "c" : 2 } }, { "x" : 1 }, { "x" : { "y" : 1 } } ], "x" : 2 }
+{ "_id" : 5, "a" : { "b" : 1, "x" : 1 }, "x" : 2 }
+{ "_id" : 6, "a" : { "b" : [ 1, 2 ], "x" : 2 }, "x" : 3 }
+{ "_id" : 8, "a" : [ { "b" : 1, "x" : 1 }, { "x" : 2 } ], "x" : 3 }
+{ "_id" : 9, "a" : [ 1, 2, { "b" : 1 }, { "b" : 2 } ], "x" : 1 }
+
+
+[jsTest] ----
+[jsTest] Query: [ { "$match" : { "$or" : [ { "a.b.c" : 1 }, { "a.x.y" : 1 } ] } } ]
+[jsTest] ----
+
+{ "_id" : 12, "a" : { "b" : { "c" : 1, "x" : 1 }, "x" : 1 }, "x" : 1 }
+{ "_id" : 13, "a" : [ 1, 2, { "b" : [ 2, { "c" : 1 }, { "c" : 2 }, { "x" : 1 } ] } ], "x" : 2 }
+{ "_id" : 14, "a" : [ 1, 2, { "b" : 1 }, { "b" : { "c" : 1 } }, { "b" : { "c" : 2 } }, { "x" : 1 }, { "x" : { "y" : 1 } } ], "x" : 2 }
+{ "_id" : 15, "a" : [ { "b" : [ { "c" : [ 1, 2 ] } ] } ] }
+
+
+[jsTest] ----
+[jsTest] Query: [ { "$match" : { "$or" : [ { "a.b.c" : 1 }, { "a.b.x" : 1 } ] } } ]
+[jsTest] ----
+
+{ "_id" : 12, "a" : { "b" : { "c" : 1, "x" : 1 }, "x" : 1 }, "x" : 1 }
+{ "_id" : 13, "a" : [ 1, 2, { "b" : [ 2, { "c" : 1 }, { "c" : 2 }, { "x" : 1 } ] } ], "x" : 2 }
+{ "_id" : 14, "a" : [ 1, 2, { "b" : 1 }, { "b" : { "c" : 1 } }, { "b" : { "c" : 2 } }, { "x" : 1 }, { "x" : { "y" : 1 } } ], "x" : 2 }
+{ "_id" : 15, "a" : [ { "b" : [ { "c" : [ 1, 2 ] } ] } ] }
+
+
+[jsTest] ----
+[jsTest] Query: [ { "$match" : { "$or" : [ { "a.b" : 1 }, { "a.b.c" : 2 } ] } } ]
+[jsTest] ----
+
+{ "_id" : 10, "a" : [ { "b" : [ 1, 2 ], "x" : 1 }, { "x" : 2 } ], "x" : 3 }
+{ "_id" : 13, "a" : [ 1, 2, { "b" : [ 2, { "c" : 1 }, { "c" : 2 }, { "x" : 1 } ] } ], "x" : 2 }
+{ "_id" : 14, "a" : [ 1, 2, { "b" : 1 }, { "b" : { "c" : 1 } }, { "b" : { "c" : 2 } }, { "x" : 1 }, { "x" : { "y" : 1 } } ], "x" : 2 }
+{ "_id" : 15, "a" : [ { "b" : [ { "c" : [ 1, 2 ] } ] } ] }
+{ "_id" : 5, "a" : { "b" : 1, "x" : 1 }, "x" : 2 }
+{ "_id" : 6, "a" : { "b" : [ 1, 2 ], "x" : 2 }, "x" : 3 }
+{ "_id" : 8, "a" : [ { "b" : 1, "x" : 1 }, { "x" : 2 } ], "x" : 3 }
+{ "_id" : 9, "a" : [ 1, 2, { "b" : 1 }, { "b" : 2 } ], "x" : 1 }
+
+
+[jsTest] ----
+[jsTest] Query: [ { "$match" : { "$or" : [ { "a" : 1 }, { "x" : 2 } ] } } ]
+[jsTest] ----
+
+{ "_id" : 0, "x" : 2 }
+{ "_id" : 1, "a" : 1, "x" : 2 }
+{ "_id" : 13, "a" : [ 1, 2, { "b" : [ 2, { "c" : 1 }, { "c" : 2 }, { "x" : 1 } ] } ], "x" : 2 }
+{ "_id" : 14, "a" : [ 1, 2, { "b" : 1 }, { "b" : { "c" : 1 } }, { "b" : { "c" : 2 } }, { "x" : 1 }, { "x" : { "y" : 1 } } ], "x" : 2 }
+{ "_id" : 3, "a" : [ 1 ], "x" : 1 }
+{ "_id" : 4, "a" : [ 1, 2, 3, "1" ] }
+{ "_id" : 5, "a" : { "b" : 1, "x" : 1 }, "x" : 2 }
+{ "_id" : 9, "a" : [ 1, 2, { "b" : 1 }, { "b" : 2 } ], "x" : 1 }
+
+
+[jsTest] ----
+[jsTest] Query: [ { "$match" : { "$or" : [ { "a" : 1 }, { "a" : 2 }, { "a.b" : 1 }, { "x" : 2 } ] } } ]
+[jsTest] ----
+
+{ "_id" : 0, "x" : 2 }
+{ "_id" : 1, "a" : 1, "x" : 2 }
+{ "_id" : 10, "a" : [ { "b" : [ 1, 2 ], "x" : 1 }, { "x" : 2 } ], "x" : 3 }
+{ "_id" : 13, "a" : [ 1, 2, { "b" : [ 2, { "c" : 1 }, { "c" : 2 }, { "x" : 1 } ] } ], "x" : 2 }
+{ "_id" : 14, "a" : [ 1, 2, { "b" : 1 }, { "b" : { "c" : 1 } }, { "b" : { "c" : 2 } }, { "x" : 1 }, { "x" : { "y" : 1 } } ], "x" : 2 }
+{ "_id" : 3, "a" : [ 1 ], "x" : 1 }
+{ "_id" : 4, "a" : [ 1, 2, 3, "1" ] }
+{ "_id" : 5, "a" : { "b" : 1, "x" : 1 }, "x" : 2 }
+{ "_id" : 6, "a" : { "b" : [ 1, 2 ], "x" : 2 }, "x" : 3 }
+{ "_id" : 8, "a" : [ { "b" : 1, "x" : 1 }, { "x" : 2 } ], "x" : 3 }
+{ "_id" : 9, "a" : [ 1, 2, { "b" : 1 }, { "b" : 2 } ], "x" : 1 }
+
+
+[jsTest] ----
+[jsTest] Query: [ { "$match" : { "$or" : [ { "_id" : { "$exists" : true } }, { "a" : 1 } ] } } ]
+[jsTest] ----
+
+{ "_id" : 0, "x" : 2 }
+{ "_id" : 1, "a" : 1, "x" : 2 }
+{ "_id" : 10, "a" : [ { "b" : [ 1, 2 ], "x" : 1 }, { "x" : 2 } ], "x" : 3 }
+{ "_id" : 11, "a" : [ { "b" : { "d" : [ 1, 2, 3 ] }, "x" : 1 }, { "x" : 2 } ], "x" : 3 }
+{ "_id" : 12, "a" : { "b" : { "c" : 1, "x" : 1 }, "x" : 1 }, "x" : 1 }
+{ "_id" : 13, "a" : [ 1, 2, { "b" : [ 2, { "c" : 1 }, { "c" : 2 }, { "x" : 1 } ] } ], "x" : 2 }
+{ "_id" : 14, "a" : [ 1, 2, { "b" : 1 }, { "b" : { "c" : 1 } }, { "b" : { "c" : 2 } }, { "x" : 1 }, { "x" : { "y" : 1 } } ], "x" : 2 }
+{ "_id" : 15, "a" : [ { "b" : [ { "c" : [ 1, 2 ] } ] } ] }
+{ "_id" : 16, "a" : [ [ 1, { "b" : [ 1, 2, { "c" : 1 }, { "c" : 2 } ] } ] ] }
+{ "_id" : 2, "a" : { "c" : 1 } }
+{ "_id" : 3, "a" : [ 1 ], "x" : 1 }
+{ "_id" : 4, "a" : [ 1, 2, 3, "1" ] }
+{ "_id" : 5, "a" : { "b" : 1, "x" : 1 }, "x" : 2 }
+{ "_id" : 6, "a" : { "b" : [ 1, 2 ], "x" : 2 }, "x" : 3 }
+{ "_id" : 7, "a" : { "b" : [ 2, 3 ], "x" : 3 }, "x" : 4 }
+{ "_id" : 8, "a" : [ { "b" : 1, "x" : 1 }, { "x" : 2 } ], "x" : 3 }
+{ "_id" : 9, "a" : [ 1, 2, { "b" : 1 }, { "b" : 2 } ], "x" : 1 }
+
+
+[jsTest] ----
+[jsTest] Query: [ { "$match" : { "$or" : [ { }, { "a" : 1 } ] } } ]
+[jsTest] ----
+
+{ "_id" : 0, "x" : 2 }
+{ "_id" : 1, "a" : 1, "x" : 2 }
+{ "_id" : 10, "a" : [ { "b" : [ 1, 2 ], "x" : 1 }, { "x" : 2 } ], "x" : 3 }
+{ "_id" : 11, "a" : [ { "b" : { "d" : [ 1, 2, 3 ] }, "x" : 1 }, { "x" : 2 } ], "x" : 3 }
+{ "_id" : 12, "a" : { "b" : { "c" : 1, "x" : 1 }, "x" : 1 }, "x" : 1 }
+{ "_id" : 13, "a" : [ 1, 2, { "b" : [ 2, { "c" : 1 }, { "c" : 2 }, { "x" : 1 } ] } ], "x" : 2 }
+{ "_id" : 14, "a" : [ 1, 2, { "b" : 1 }, { "b" : { "c" : 1 } }, { "b" : { "c" : 2 } }, { "x" : 1 }, { "x" : { "y" : 1 } } ], "x" : 2 }
+{ "_id" : 15, "a" : [ { "b" : [ { "c" : [ 1, 2 ] } ] } ] }
+{ "_id" : 16, "a" : [ [ 1, { "b" : [ 1, 2, { "c" : 1 }, { "c" : 2 } ] } ] ] }
+{ "_id" : 2, "a" : { "c" : 1 } }
+{ "_id" : 3, "a" : [ 1 ], "x" : 1 }
+{ "_id" : 4, "a" : [ 1, 2, 3, "1" ] }
+{ "_id" : 5, "a" : { "b" : 1, "x" : 1 }, "x" : 2 }
+{ "_id" : 6, "a" : { "b" : [ 1, 2 ], "x" : 2 }, "x" : 3 }
+{ "_id" : 7, "a" : { "b" : [ 2, 3 ], "x" : 3 }, "x" : 4 }
+{ "_id" : 8, "a" : [ { "b" : 1, "x" : 1 }, { "x" : 2 } ], "x" : 3 }
+{ "_id" : 9, "a" : [ 1, 2, { "b" : 1 }, { "b" : 2 } ], "x" : 1 }
+
+
+[jsTest] ----
+[jsTest] Query: [ { "$match" : { "$or" : [ { "_id" : { "$exists" : false } }, { "a" : 1 } ] } } ]
+[jsTest] ----
+
+{ "_id" : 1, "a" : 1, "x" : 2 }
+{ "_id" : 13, "a" : [ 1, 2, { "b" : [ 2, { "c" : 1 }, { "c" : 2 }, { "x" : 1 } ] } ], "x" : 2 }
+{ "_id" : 14, "a" : [ 1, 2, { "b" : 1 }, { "b" : { "c" : 1 } }, { "b" : { "c" : 2 } }, { "x" : 1 }, { "x" : { "y" : 1 } } ], "x" : 2 }
+{ "_id" : 3, "a" : [ 1 ], "x" : 1 }
+{ "_id" : 4, "a" : [ 1, 2, 3, "1" ] }
+{ "_id" : 9, "a" : [ 1, 2, { "b" : 1 }, { "b" : 2 } ], "x" : 1 }
+
+
+[jsTest] ----
+[jsTest] Query: [ { "$match" : { "$or" : [ { "$or" : [ { "a.b" : 1 }, { "a.b" : 2 } ] }, { "$and" : [ { "x" : { "$exists" : true } }, { "a" : { "$exists" : true } } ] } ] } } ]
+[jsTest] ----
+
+{ "_id" : 1, "a" : 1, "x" : 2 }
+{ "_id" : 10, "a" : [ { "b" : [ 1, 2 ], "x" : 1 }, { "x" : 2 } ], "x" : 3 }
+{ "_id" : 11, "a" : [ { "b" : { "d" : [ 1, 2, 3 ] }, "x" : 1 }, { "x" : 2 } ], "x" : 3 }
+{ "_id" : 12, "a" : { "b" : { "c" : 1, "x" : 1 }, "x" : 1 }, "x" : 1 }
+{ "_id" : 13, "a" : [ 1, 2, { "b" : [ 2, { "c" : 1 }, { "c" : 2 }, { "x" : 1 } ] } ], "x" : 2 }
+{ "_id" : 14, "a" : [ 1, 2, { "b" : 1 }, { "b" : { "c" : 1 } }, { "b" : { "c" : 2 } }, { "x" : 1 }, { "x" : { "y" : 1 } } ], "x" : 2 }
+{ "_id" : 3, "a" : [ 1 ], "x" : 1 }
+{ "_id" : 5, "a" : { "b" : 1, "x" : 1 }, "x" : 2 }
+{ "_id" : 6, "a" : { "b" : [ 1, 2 ], "x" : 2 }, "x" : 3 }
+{ "_id" : 7, "a" : { "b" : [ 2, 3 ], "x" : 3 }, "x" : 4 }
+{ "_id" : 8, "a" : [ { "b" : 1, "x" : 1 }, { "x" : 2 } ], "x" : 3 }
+{ "_id" : 9, "a" : [ 1, 2, { "b" : 1 }, { "b" : 2 } ], "x" : 1 }
+
+
+[jsTest] ----
+[jsTest] Query: [ { "$match" : { "$or" : [ { "$or" : [ { "$or" : [ { "a.b" : 1 }, { "a.b" : 2 } ] }, { "$and" : [ { "x" : { "$exists" : true } }, { "a.b.c" : { "$exists" : true } } ] } ] }, { "$and" : [ { "$or" : [ { "a.b.c" : 1 }, { "a.b.c" : 2 } ] }, { "$and" : [ { "a" : 1 }, { "a" : 2 } ] } ] } ] } } ]
+[jsTest] ----
+
+{ "_id" : 10, "a" : [ { "b" : [ 1, 2 ], "x" : 1 }, { "x" : 2 } ], "x" : 3 }
+{ "_id" : 12, "a" : { "b" : { "c" : 1, "x" : 1 }, "x" : 1 }, "x" : 1 }
+{ "_id" : 13, "a" : [ 1, 2, { "b" : [ 2, { "c" : 1 }, { "c" : 2 }, { "x" : 1 } ] } ], "x" : 2 }
+{ "_id" : 14, "a" : [ 1, 2, { "b" : 1 }, { "b" : { "c" : 1 } }, { "b" : { "c" : 2 } }, { "x" : 1 }, { "x" : { "y" : 1 } } ], "x" : 2 }
+{ "_id" : 5, "a" : { "b" : 1, "x" : 1 }, "x" : 2 }
+{ "_id" : 6, "a" : { "b" : [ 1, 2 ], "x" : 2 }, "x" : 3 }
+{ "_id" : 7, "a" : { "b" : [ 2, 3 ], "x" : 3 }, "x" : 4 }
+{ "_id" : 8, "a" : [ { "b" : 1, "x" : 1 }, { "x" : 2 } ], "x" : 3 }
+{ "_id" : 9, "a" : [ 1, 2, { "b" : 1 }, { "b" : 2 } ], "x" : 1 }
diff --git a/jstests/query_golden/match_with_and_or.js b/jstests/query_golden/match_with_and_or.js
new file mode 100644
index 00000000000..2e71e7fd47b
--- /dev/null
+++ b/jstests/query_golden/match_with_and_or.js
@@ -0,0 +1,109 @@
+/**
+ * Test $match with $and/$or is supported and returns correct results.
+ */
+
+(function() {
+"use strict";
+load("jstests/query_golden/libs/utils.js");
+
+const coll = db.and_or_coll;
+
+const docs = [
+ // No 'a' path.
+ {x: 2},
+
+ // No 'a.b' path.
+ {a: 1, x: 2},
+ {a: {c: 1}},
+ {a: [1], x: 1},
+ {a: [1, 2, 3, "1"]},
+
+ // No 'a.b.c' path.
+ {a: {b: 1, x: 1}, x: 2},
+ {a: {b: [1, 2], x: 2}, x: 3},
+ {a: {b: [2, 3], x: 3}, x: 4},
+ {a: [{b: 1, x: 1}, {x: 2}], x: 3},
+ {a: [1, 2, {b: 1}, {b: 2}], x: 1},
+ {a: [{b: [1, 2], x: 1}, {x: 2}], x: 3},
+ {a: [{b: {d: [1, 2, 3]}, x: 1}, {x: 2}], x: 3},
+
+ // 'a.b.c' path exists.
+ {a: {b: {c: 1, x: 1}, x: 1}, x: 1},
+ {a: [1, 2, {b: [2, {c: 1}, {c: 2}, {x: 1}]}], x: 2},
+ {a: [1, 2, {b: 1}, {b: {c: 1}}, {b: {c: 2}}, {x: 1}, {x: {y: 1}}], x: 2},
+ {a: [{b: [{c: [1, 2]}]}]},
+
+ // There is a double array under 'a' which should not be traversed.
+ {a: [[1, {b: [1, 2, {c: 1}, {c: 2}]}]]},
+];
+const indexes = [
+ // TODO SERVER-71524: Invalid index plans sometimes chosen by CQF cause result differences.
+ // {a: 1},
+ // {'a.b': 1},
+ // {a: 1, x: 1},
+];
+resetCollection(coll, docs, indexes);
+
+const andOrSpecs = [
+ // Where there is only one child.
+ [{a: 1}],
+ [{a: {$lt: 20}}],
+ [{a: {$lt: 20, $gt: 0}}],
+
+ // Where the predicates are over the same path.
+ [{a: 1}, {a: 2}],
+ [{a: 1}, {a: 1}],
+ [{a: {$in: [1, 3]}}, {a: {$in: [2, 4]}}],
+ [{'a.b': 1}, {'a.b': 2}],
+ [{a: {$lt: 20}}, {a: {$gt: 0}}],
+ [{a: {$gt: 0}}, {a: {$gte: 0}}],
+ [{a: {$lte: 1}}, {a: {$gte: 2}}],
+ [{a: {$lt: 20, $gt: 0}}, {a: {$lt: 10, $gt: -5}}],
+ [{a: {$gt: 1}}, {a: {$lt: "2"}}],
+ [{a: null}, {a: {$exists: false}}],
+ [{a: {$in: [1, 2, 3]}}, {a: {$in: [3, 4, 5]}}],
+
+ // Where the predicates form a contradiction.
+ [{a: 1}, {a: {$not: {$eq: 1}}}],
+ [{a: {$exists: false}}, {a: {$exists: true}}],
+ [{'a.b': {$exists: false}}, {'a.b': {$exists: true}}],
+
+ // Where the predicates are over paths with shared prefixes.
+ [{'a.b': 1}, {'a.x': 1}],
+ [{'a.b.c': 1}, {'a.x.y': 1}],
+ [{'a.b.c': 1}, {'a.b.x': 1}],
+ [{'a.b': 1}, {'a.b.c': 2}],
+
+ // Where some of the predicates are over completely disjoint paths.
+ [{a: 1}, {x: 2}],
+ [{a: 1}, {a: 2}, {'a.b': 1}, {x: 2}],
+
+ // Where one of the predicates is always-false or always-true.
+ [{_id: {$exists: true}}, {a: 1}],
+ [{/* should match everything */}, {a: 1}],
+ [{_id: {$exists: false}}, {a: 1}],
+
+ // Where the predicates are themselves ands/ors: 1 level of nesting.
+ [{$or: [{'a.b': 1}, {'a.b': 2}]}, {$and: [{x: {$exists: true}}, {a: {$exists: true}}]}],
+
+ // Where the predicates are themselves ands/ors: 2 levels of nesting.
+ [
+ {
+ $or: [
+ {$or: [{'a.b': 1}, {'a.b': 2}]},
+ {$and: [{x: {$exists: true}}, {'a.b.c': {$exists: true}}]}
+ ]
+ },
+ {$and: [{$or: [{'a.b.c': 1}, {'a.b.c': 2}]}, {$and: [{a: 1}, {a: 2}]}]}
+ ],
+];
+
+const operators = ["$and", "$or"];
+for (const op of operators) {
+ for (const andOrSpec of andOrSpecs) {
+ const pipeline = [{$match: {[op]: andOrSpec}}];
+ jsTestLog(`Query: ${tojsononeline(pipeline)}`);
+ show(coll.aggregate(pipeline));
+ }
+}
+}());