Currently, I am utilizing MongoDB through the command line on a linux system.
I have created a simple deletedata.js script which appears as follows;
//this script deletes everything
db.Collection1.deleteMany({})
db.Collection2.deleteMany({})
db.CollectionN+1.deleteMany{}
In order to delete all data from multiple collections at once, I manually log in to MongoDB using the standard login command;
mongo 'hostname'/mongodb_name --username myusername --password mypassword
Once logged into MongoDB, I execute the script using the command;
load('/home/username/deletedata.js')
The script runs successfully and all the deleteMany commands are executed. However, the only output I receive is "true".
Although I am comfortable with writing MongoDB commands, I am limited to that skill set. I am curious if it is possible to enhance the script with additional MongoDB commands and display the output within the MongoDB session on the command line?
For example, when trying to add a count() command like;
db.Collection1.find({}).count()
After running the script again using;
load('/home/username/deletedata.js')
I still only see "true" returned. How can I show the output of the count() command when it is included in the .js file and executed within MongoDB using load()?
I anticipated that the result of the mongodb .count() command would be displayed on the mongoDb command line, but the only output I get when using the mongoDb load('') command is "true" if the script runs.