...
When I try to run the aggregation below, which has a nesting of $facet -> $lookup -> $facet -> $lookup, I get the error message "$lookup is not allowed to be used within a $facet stage". This message is wrong, since $lookup is indeed allowed in a $facet stage and works fine. The problem with the pipeline is that it has a $facet inside a $facet, which is not allowed. This is the pipeline that results in the wrong error message: db.data.aggregate([ { "$facet" : { "result" : [ { "$match" : { "ref1" : { "$exists" : true }}}, { "$lookup" : { "from" : "data", "localField" : "ref1", "foreignField" : "_id", "pipeline" : [ { "$facet" : { "result" : [ { "$match" : { "ref2" : { "$exists" : true }}}, { "$lookup" : { "from" : "data", "localField" : "ref2", "foreignField" : "_id", "as" : "ref2" }}]}}], "as" : "ref1" }}]}}]) On the other hand, for a pipeline with a $facet immediately nested within another $facet, the message is correct. This pipeline: db.data.aggregate([{"$facet" : { "x" : [ {"$facet" : { "y" : [] }}]}}]) results in the correct message "$facet is not allowed to be used within a $facet stage" The problem is the same in both 6.0.6 and 7.0.0.
xgen-internal-githook commented on Wed, 3 Apr 2024 08:42:35 +0000: Author: {'name': 'mivanova3', 'email': '68105381+mivanova3@users.noreply.github.com', 'username': 'mivanova3'} Message: SERVER-80456 Fix error message when using $facet inside $facet (#19690) GitOrigin-RevId: f90797eedfbc172948063d8210f4b70a093248ee Branch: master https://github.com/mongodb/mongo/commit/84cd21794e55ad2521bc58711f9204ceda8eafb5
MongoDB Integration
Learn more about where this data comes from
Bug Scrub Advisor
Streamline upgrades with automated vendor bug scrubs
BugZero Enterprise
Wish you caught this bug sooner? Get proactive today.