In this blog, I am going to show an example for the same:
print(‘===== My Demo Script =====’);
print(db.getCollectionNames()); // prints all collection names in respective database
print(db.myCollection.count()); // prints the count of myCollection collection.
shell command to execute the script –
mongo 127.0.0.1/my-profile-db –username=’username’ –password=’pwd’ mongodb-script.js
mongodb-script.js is the shell script.
Basically this is just a regular mongodb connection command executing the script (after establishing successful connection).
In my next blog I will discuss an advance use-case – exporting collection records using shell script.