Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.