mesh - MongoDB Extended Shell
Description
mesh (MongoDB Extended Shell) is a javascript file that extends the mongo shell. It includes some useful libraries, as well as new functions for dealing with Mongo collections and queries.
What’s Included?
-
underscore.js - Underscore.js is a utility-belt library for JavaScript that provides support for the usual functional suspects (each, map, reduce, filter…) without extending any core JavaScript objects.
-
underscore.string.js - Javascript lacks complete string manipulation operations. This an attempt to fill that gap.
-
moment.js - A lightweight javascript date library for parsing, validating, manipulating, and formatting dates.
-
science.js - Scientific and statistical computing in JavaScript.
-
distinct2() - Similar to the built-in distinct() function, but with more capabilities.
-
distinctTypes() - Similar to the db.myCollection.distinct() function, distinctTypes() will return “types” rather than “values”.
-
flatten() - The flatten() function is a mapReduce that flattens documents into key/value pairs.
-
schema() - A schema analysis tool for MongoDB.
-
wild() - Adds a wildcard search to the mongodb shell.
-
A console wrapper so calls like console.log() and console.dir() don’t error out
-
mesh.setPrompt(): a way to configure your prompt. Can set a default in mesh.config.js
-
mesh.keys(): will return all the “global” properties as a sorted array.
-
JSON-js - JSON.stringify() and JSON.parse()
-
mesh.oid() - a wrapper for ObjectId()
-
mesh.tid() - a wrapper for creating ObjectId values based on a timestamp
-
a few underscore.js mixins
-
DBCollection.insertArray() - insert an array of objects into a collection
Installation
Download: mesh.js
Option 1
Add this script to your .mongorc.js file.
Example .mongorc.js:
load('mesh.js');
load('mesh.config.js');
Option 2
Start the shell after executing this script
mongo --shell mesh.js
Configuration
You can configure mesh by calling mesh.config(settings). The benefit of keeping a config file, is that you won’t lose your default settings when updating mesh. Currently, there are 2 config values: defaultPrompt and aliases.
You can create a file “mesh.config.js”. It might look like:
mesh.config({
defaultPrompt : 4, // 0-4 or a string
aliases : { // can pass in a map of aliases.
't' : 'mesh.tid', // t() is an alias for mesh.tid()
'o' : 'ObjectId', // o() is an alias for ObjectId()
'm' : 'mesh' // m is an alias for mesh
}
});
Now, when starting the shell, you can pass in the mesh.config.js file along with your mesh.js file like:
mongo --shell mesh.js mesh.config.js
Or if you are using .mongorc.js:
load('mesh.js');
load('mesh.config.js');
Usage
coming soon
For Developers
Getting The Code
git clone git://github.com/skratchdot/mesh.git
cd mesh
git submodule update --init --recursive
Updating submodule sources
git submodule foreach git pull
Version History
v1.4.3 - Released March 7, 2013
* adding mesh.ops which prints all operations. * no longer printing version when tabbing. * updating the following libraries: JSON-js, moment, distinct2(), schema(), and underscore.js
v1.4.2 - Released February 7, 2013
* updating the following libraries: moment, science.js, underscore.js, and underscore.string.js
v1.4.1 - Released December 10, 2012
* adding DBCollection.insertArray() * adding JSON-js - json2.js and cycle.js * updating distinct2(), underscore.js, and moment.js
v1.4.0 - Released December 9, 2012
* updating distinct2() * adding some underscore.js mixins - underscore.aggregate.js - underscore.avg.js - underscore.deepExtend.js - underscore.deepPluck.js - underscore.keyToObject.js - underscore.stdev.js - underscore.sum.js - underscore.variance.js
v1.3.1 - Released November 15, 2012
* adding mesh.setAliases() * removing globalTid and globalOid from mesh.config in favor of using ‘aliases’. * mesh.tid() now accepts an optional “increment” argument * reload mesh each time load(‘mesh.js’) is called * fixing build process (version and date replaced) * fixing bug w/ how hostname is determined in prompt * removing moment() / window hack
v1.3.0 - Released November 13, 2012
* updating libraries: moment.js, distinct2(), underscore.js, and underscore.string.js * adding mesh.oid() - a wrapper for ObjectId() * adding mesh.tid() - a wrapper for creating ObjectId values based on a timestamp * config values to change mesh.tid() to t() or mesh.oid() to o()
v1.2.4 - Released October 22, 2012
* updating libraries: flatten() and underscore.js
v1.2.3 - Released October 21, 2012
* updating libraries: flatten()
v1.2.2 - Released October 20, 2012
* updating libraries: flatten(), underscore.js, and underscore.string.js
v1.2.1 - Released October 7, 2012
* updating libraries: moment.js, distinct2(), and underscore.js * json2.js is now included due to the distinct2() upgrade
v1.2.0 - Released September 24, 2012
* mesh.setPrompt() is now mesh.prompt() * updating libraries * adding mesh.time() which displays function execution times
v1.1.4 - Released August 20, 2012
* removing Sugar (rely on underscore.js instead) * updating submodules
v1.1.3 - Released August 16, 2012
* adding science.js
v1.1.2 - Released August 16, 2012
* Mix in non-conflicting string functions to the Underscore namespace * adding Sugar * using minified version of moment.js
v1.1.1 - Released August 16, 2012
* Updating submodules * Updating README.md with “What’s Included?” descriptions * Updating README.md with “For Deveopers” section * Small fix to distinct2.js
v1.1.0 - Released August 15, 2012
* Adding distinct2.js * implementing mesh.toString() so the console prints help info
v1.0.0 - Released July 17, 2012
* Initial Release
