I have several js files with collections creations and seeds. I load data from one of them using, for example,
mongo <host>:<port>/<database> -u <user> -p <password> < db.users.js
However, now I have several files, and I wish I could load all of them to mongo using one command. Hopefully, with mongo shell.
Is there any way I can do it?
mongoshell: You can create an array of the js file names. Then use theload()to run the js scripts in a loop, e.g.,for (let file of jsfiles) load(file).mongo localhost/test script1.js script2.jsdb.createCollection('users')