(InvalidNamespace) {aggregate: 1} is not valid for '$addFields'; a collection is required

Here is the exact test case/ error in mongosh:

> db.version()
<7.2.0
>db.aggregate([
{"$documents": {"$literal": [{a: 1}]}},
{"$merge": {"into": "test", "on": ["_id"], "whenMatched": [
	{ "$addFields"    : {"_merged"              : "$$new"}}
]}}
 ])
<MongoServerError: {aggregate: 1} is not valid for '$addFields'; a collection is required.

It was working just fine earlier last week, not clear what version it was

1 Like