How to script the Mongo shell

I have seen many of us type out long and convoluted mongo shell commands to view small world records. I learnt today that the mongo shell can be scripted using javascript and can be used to create short cuts for often used long command. For e.g. the attached file contains four helper routines to quickly look at a mongo record. Edit the script for any port and server parameters.

Start mongo like: $ mongo sw.js --shell

Then you can do something as simple as the following on the mongo prompt.

> getId("4FCD3FCDE44D78692F22EC9A")
> getId_p("4FCD3FCDE44D78692F22EC9A") 

The second one pretty prints the object. Hope this is of some use.

More help can be found here: http://docs.mongodb.org/manual/tutorial/write-scripts-for-the-mongo-shell/