Skip to content

Instantly share code, notes, and snippets.

@jrschumacher
Forked from vidoss/gist:2178987
Last active August 29, 2015 13:57
Show Gist options
  • Save jrschumacher/9354327 to your computer and use it in GitHub Desktop.
Save jrschumacher/9354327 to your computer and use it in GitHub Desktop.
MongoDB provides a Javascript shell. But Javascript is no fun without Underscore.js (http://underscorejs.org/). Here is how to add Underscore.js

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. Download or clone 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
  1. Use underscore to write your db script file (say my_commands.js)
_.each(db.dbname.find().toArray(), function(itm) { ... })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment