...
This applies to 5.0.2-rc0 I have narrowed down that this is not an issue with matching on nested document fields in isolation (they work fine), and also, if the nested results from the unwound lookup result are projected into the root document and the match applied to the root document, it works correctly. Additionally, matches on the fields from the current document of the $lookup (rather than the $lookup result) work correctly. This is the specific situation, minimized, as far as I can tell. Here is a repo query with data (showing results in 4.4 and 5.0.2-rc0) Data: > db.strings.find() { "_id" : ObjectId("611017e028ec416850edf3dc"), "a" : "" } { "_id" : ObjectId("611017e328ec416850edf3dd"), "a" : "foo" } 4.4-latest: > db.strings.aggregate([{"$lookup": {"from": "strings","let": {},"pipeline": [],"as": "o"}}, {$unwind: "$o"}, {$match: {"o.a": {$ne: ""}}}]) { "_id" : ObjectId("61101a3728ec416850edf3df"), "a" : "", "o" : { "_id" : ObjectId("61101a3d28ec416850edf3e0"), "a" : "foo" } } { "_id" : ObjectId("61101a3d28ec416850edf3e0"), "a" : "foo", "o" : { "_id" : ObjectId("61101a3d28ec416850edf3e0"), "a" : "foo" } } 5.0.2-rc0: > db.strings.aggregate([{"$lookup": {"from": "strings","let": {},"pipeline": [],"as": "o"}}, {$unwind: "$o"}, {$match: {"o.a": {$ne: ""}}}]) { "_id" : ObjectId("611017e028ec416850edf3dc"), "a" : "", "o" : { "_id" : ObjectId("611017e028ec416850edf3dc"), "a" : "" } } { "_id" : ObjectId("611017e028ec416850edf3dc"), "a" : "", "o" : { "_id" : ObjectId("611017e328ec416850edf3dd"), "a" : "foo" } } { "_id" : ObjectId("611017e328ec416850edf3dd"), "a" : "foo", "o" : { "_id" : ObjectId("611017e028ec416850edf3dc"), "a" : "" } } { "_id" : ObjectId("611017e328ec416850edf3dd"), "a" : "foo", "o" : { "_id" : ObjectId("611017e328ec416850edf3dd"), "a" : "foo" } }
JIRAUSER1259052 commented on Wed, 6 Oct 2021 18:09:29 +0000: Updating the fixversion since branching activities occurred yesterday. This ticket will be in rc0 when it’s been triggered. For more active release information, please keep an eye on #server-release. Thank you! xgen-internal-githook commented on Fri, 24 Sep 2021 19:23:30 +0000: Author: {'name': 'Katherine Wu', 'email': 'katherine.wu@mongodb.com', 'username': 'kaywux'} Message: SERVER-59308 Ensure empty $lookup subpipeline optimizes correctly with subsequent $match (cherry picked from commit d5156d91a608a3b7cf30fbdb63a2d31783389a47) Branch: v5.0 https://github.com/mongodb/mongo/commit/602f7cf6baa8c43e8f3791a1a5ed09f5f42d104c xgen-internal-githook commented on Wed, 15 Sep 2021 19:05:07 +0000: Author: {'name': 'Katherine Wu', 'email': 'katherine.wu@mongodb.com', 'username': 'kaywux'} Message: SERVER-59308 Ensure empty $lookup subpipeline optimizes correctly with subsequent $match Branch: master https://github.com/mongodb/mongo/commit/d5156d91a608a3b7cf30fbdb63a2d31783389a47 patrick.meredith commented on Thu, 12 Aug 2021 17:24:40 +0000: This problem also exists in 5.0.0 ga. patrick.meredith commented on Wed, 11 Aug 2021 23:45:59 +0000: My best guess is that we have an issue in the optimizer rewrites with dropping the $match, but that is not guaranteed to be the issue