I tried to reproduce your results from the shell, but I wasn’t successful. The script I ran for local testing is here. I was testing against a single node replicaset with server version 4.4.1. You mentioned your command works in the shell, so can you see if my script differs from the commands you ran at all? If you want to run the script I linked, you can download it, start up a cluster, and run mongo main.js.