Unrecognized pipeline stage name: '$unionWith'

Hi community. I’m using “mongodb”: “^4.4.1” version for Node.JS and i’m trying to make the following query :

db.collection('myCollection').aggregate([{ $unionWith: {coll: 'anotherCollection'} }])  

But i have the following error : “Unrecognized pipeline stage name: ‘$unionWith’”

Do you know why please ? :frowning: Thank you

Hi @Mickael_TORDJMAN1,
You’re using Node.js driver version 4.4.
What MongoDB version are you using?
Thanks,
Rafael,

1 Like

Capture d’écran 2022-04-02 à 22.37.20
@Rafael_Green Hi ! Thank your for your answer :pray:

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.

module.exports = {
  mongodbMemoryServerOptions: {
    binary: {
      version: '5.0.6',
      skipMD5: true,
    },
    autoStart: false,
    instance: {},
  },
};

It’s working perfectly now.

Thank for your time and have a good day.

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.