$merge with whenMatched but no "on"

There’s an example in the docs under “Use Variables Defined in the Merge Stage” where $merge is shown with a whenMatched, but there was no “on” specified.

What’s the behavior when there is no “on” (which is indeed optional) – does the whenMatched action (in this case a pipeline) just always get executed?

Thanks

2 Likes

Hi,

In the same documentation, you can see that on has a default value that depends on the output collection.

The default value for on depends on the output collection:

  • If the output collection does not exist, the on identifier must be and defaults to the _id field. The corresponding unique _id index is automatically created.
  • If the existing output collection is unsharded, the on identifier defaults to the _id field.
  • If the existing output collection is a sharded collection, the on identifier defaults to all the shard key fields and the _id field. If specifying a different on identifier, the on must contain all the shard key fields.
2 Likes

Thanks - missed that!

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