[skratchdot.]


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.

Installation

Download: mesh.js

Option 1

Add this script to your .mongorc.js file.

See: http://www.mongodb.org/display/DOCS/Overview+-+The+MongoDB+Interactive+Shell#Overview-TheMongoDBInteractiveShell-.mongorc.js

Example .mongorc.js:

load('mesh.js');
load('mesh.config.js');

Option 2

Start the shell after executing this script

mongo --shell mesh.js

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

  • mesh.idrange.js - search collections for documents with ids created between 2 datetimes

  • mesh.sizeinfo.js - reports the count/sum/avg/max/min of all bson sizes for the given query/collection.

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

Building mesh.js

npm install
grunt

Version History

v1.5.0 - Released September 25, 2013

v1.4.3 - Released March 7, 2013

v1.4.2 - Released February 7, 2013

v1.4.1 - Released December 10, 2012

v1.4.0 - Released December 9, 2012

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

v1.2.3 - Released October 21, 2012

v1.2.2 - Released October 20, 2012

v1.2.1 - Released October 7, 2012

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

v1.1.3 - Released August 16, 2012

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