How to run script in MongoDB both in onpremise and atlas

Use the MongoDB Shell mongosh

  • You can use mongosh as a command-line tool to connect to your cluster in order to:
    • issue interactive queries
    • load and run scripts
  • You can run mongosh from within Compass, the MongoDB Gui