UpdateMany throws error for update multiple documents


await collectionName.updateMany({
  user: userId,
}, records, {upsert: true});

// records here are array of object belonging to the userId which need to be updated / created
// records does have userId in each of the document 

The below error is thrown

Error: Invalid update pipeline operator: “chain”

This error also occurs with updateOne and update

Looks like the format of your query is a bit off, see:

So the second part “records” should be the actions you want to take on documents that match user:userID.

So for example if I wanted to add a field, called “Name is John” to documents, I could do this:

            'Name is John':true

What exactly does your update statement looks like, as well as the document before what you expect it to look like?