Posted at

mongoのコマンドをファイルに書いてCLIで実行する

#!/bin/bash

host=## YOUR MONGO HOST ##
port=## YOUR MONGO PORT NUMBER ##
database=## YOUR MONGO DATABASE ##
user=## MONGO USER ##
pass=## PASSWORD ##
run_commands=commands.js

mongo ${host}:${port}/${database} -u $user -p $pass < $run_commands


commands.js

show collections

query = { email: "user@example.com" }
db.events.find(query).limit(20)