Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

joelgrus commented Oct 18, 2013

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

@JunheeK

This comment has been minimized.

Copy link

JunheeK commented Sep 22, 2015

Thank you so much, this is gold!

@amir-clever

This comment has been minimized.

Copy link

amir-clever commented Nov 26, 2016

Amazing. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.