I’m using on my localhost 5.0.6 MongoDB, and with MongoCompass i can aggregate with unionWith stage. But i can’t use it with the mongodb driver 4.4.1 .
That is very strange since $unionWith is interpreted by the server. So if you are connected to the same server you should get the same behavior. As far as your nodejs code is concerned your aggregation pipeline is simply a json document that is given as an argument to aggregate and is shipped more or less as-is to the server.
Post a screenshot that shows that Compass is connected to your local host while you do $unionWith. Also post a mongo shell session transcript that shows you connect to local host and that $unionWith does not work.
Okay, i found the solution, it’s my fault i made a mistake. It was working perfectly at node.js runtime, but the error was thrown during the jest unit tests. Because i forgot to update the mongodb memory server version for jest usage.