Hi,
i want to create a batch script which runs all create database, create collection and inserting, deleting data etc. commands, but i have not found any reference on this anywhere……………..i really need it…..
i have written a script for starting the database automatically but want to run all queries…the starting mongoDB script is here…
One way to achieve this is to use scripting on the mongo shell. For example, to insert a document {x:1} into a collection coll in database test and print the content of the collection, you can create a script called e.g. script.js, which contains:
db = db.getSiblingDB('test')
db.coll.insert({x:1})
result = db.coll.find().toArray()
printjson(result)
and run the script from the command line or inside a batch script:
mongo script.js
Please note that any shell helper command such as use db or show collections does not work in a mongo shell script. This is explained in the Differences between Interactive and Scripted mongo page.
You may find these links helpful:
mongo shell pagemongo shell pageBest regards,
Kevin