Skip to content

Instantly share code, notes, and snippets.

@vidoss
Created March 24, 2012 06:20
Show Gist options
  • Star 22 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save vidoss/2178987 to your computer and use it in GitHub Desktop.
Save vidoss/2178987 to your computer and use it in GitHub Desktop.
Using underscore.js while scripting mongodb shell.
MongoDB provides a Javascript shell. But Javascript is no fun without underscore.js
Turned out its straight forward to use underscore.js while scripting mongodb.
Here are the steps.
1) Use underscore to write your db script file (say my_commands.js)
E.g: _.each(db.dbname.find().toArray(), function(itm) { ... })
2) Download underscore.js and run...
%mongo server:27017/dbname underscore.js my_commands.js
OR if you just want undrescore.js in your shell prompt
%mongo server:27017/dbname underscore.js --shell
@joelgrus
Copy link

Thanks, I was looking for how to do this, this is awesome!

@JunheeK
Copy link

JunheeK commented Sep 22, 2015

Thank you so much, this is gold!

@amir-clever
Copy link

Amazing. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment