There are terminology issues with your post that makes it hard to understand.
You write that you have 2 docs, but use $merge which is a collection operation.
You also write that it works in 4.2.
Assuming doc1 and doc2 are really collections, I suspect that you forgot to switch to the database that contains your collections with the use command and that you are using the local database which is reserved. It worked in 4.2 simply because you did the appropriate use TheCorrectDatabase before the $merge.
it is nice thing you use mongosh because it shows you which database is currently active: local is your current one because at some point you have used use local command.
Please use/create some other database name for your needs, such as mergingdb and switch to it with use mergingdb for your operations. rest assured your query works that way.