document/probe.js
function pushin( path, record, setter, newValue ) {
	var context = record;
	var parent = record;
	var lastPart = null;
	var _i;
	var _len;
	var part;
	var keys;

	for ( _i = 0, _len = path.length; _i < _len; _i++ ) {
		part = path[_i];
		lastPart = part;
		parent = context;
		context = context[part];
		if ( sys.isNull( context ) || sys.isUndefined( context ) ) {
			parent[part] = {};
			context = parent[part];
		}
	}

	if ( sys.isEmpty( setter ) || setter === '$set' ) {
		parent[lastPart] = newValue;
		return parent[lastPart];
	} else {
		switch ( setter ) {
			case '$inc':
				/**
				 * Increments a field by the amount you specify. It takes the form
				 * `{ $inc: { field1: amount } }`
				 * @name $inc
				 * @memberOf module:document/probe.updateOperators
				 * @example
				 * var probe = require("document/probe");
				 * probe.update( obj, {'name.last' : 'Owen', 'name.first' : 'LeRoy'},
				 * {$inc : {'password.changes' : 2}} );
				 */

				if ( !sys.isNumber( newValue ) ) {
					newValue = 1;
				}
				if ( sys.isNumber( parent[lastPart] ) ) {
					parent[lastPart] = parent[lastPart] + newValue;
					return parent[lastPart];
				}
				break;
			case '$dec':
				/**
				 * Decrements a field by the amount you specify. It takes the form
				 * `{ $dec: { field1: amount }`
                 * @name $dec
				 * @memberOf module:document/probe.updateOperators
				 * @example
				 *  var probe = require("document/probe");
				 * probe.update( obj, {'name.last' : 'Owen', 'name.first' : 'LeRoy'},
				 * {$dec : {'password.changes' : 2}} );
				 */

				if ( !sys.isNumber( newValue ) ) {
					newValue = 1;
				}
				if ( sys.isNumber( parent[lastPart] ) ) {
					parent[lastPart] = parent[lastPart] - newValue;
					return parent[lastPart];
				}
				break;
			case '$unset':
				/**
				 * Removes the field from the object. It takes the form
				 * `{ $unset: { field1: "" } }`
				 * @name $unset
				 * @memberOf module:document/probe.updateOperators
				 * @example
				 * var probe = require("document/probe");
				 * probe.update( data, {'name.first' : 'Yogi'}, {$unset : {'name.first' : ''}} );
				 */

				return delete parent[lastPart];
			case '$pop':
				/**
				 * The $pop operator removes the first or last element of an array. Pass $pop a value of 1 to remove the last element
				 * in an array and a value of -1 to remove the first element of an array. This will only work on arrays. Syntax:
				 * `{ $pop: { field: 1 } }` or `{ $pop: { field: -1 } }`
				 * @name $pop
				 * @memberOf module:document/probe.updateOperators
				 * @example
				 * var probe = require("document/probe");
				 * // attr is the name of the array field
				 * probe.update( data, {_id : '511d18827da2b88b09000133'}, {$pop : {attr : 1}} );
				 */

				if ( sys.isArray( parent[lastPart] ) ) {
					if ( !sys.isNumber( newValue ) ) {
						newValue = 1;
					}
					if ( newValue === 1 ) {
						return parent[lastPart].pop();
					} else {
						return parent[lastPart].shift();
					}
				}
				break;
			case '$push':
				/**
				 * The $push operator appends a specified value to an array. It looks like this:
				 * `{ $push: { <field>: <value> } }`
				 * @name $push
				 * @memberOf module:document/probe.updateOperators
				 * @example
				 * var probe = require("document/probe");
				 * // attr is the name of the array field
				 * probe.update( data, {_id : '511d18827da2b88b09000133'},
				 * {$push : {attr : {"hand" : "new", "color" : "new"}}} );
				 */

				if ( sys.isArray( parent[lastPart] ) ) {
					return parent[lastPart].push( newValue );
				}
				break;
			case '$pull':
				/**
				 * The $pull operator removes all instances of a value from an existing array. It looks like this:
				 * `{ $pull: { field: <query> } }`
				 * @name $pull
				 * @memberOf module:document/probe.updateOperators
				 * @example
				 * var probe = require("document/probe");
				 * // attr is the name of the array field
				 * probe.update( data, {'email' : 'EWallace.43@fauxprisons.com'},
				 * {$pull : {attr : {"color" : "green"}}} );
				 */

				if ( sys.isArray( parent[lastPart] ) ) {
					keys = exports.findKeys( parent[lastPart], newValue );
					sys.each( keys, function ( val, index ) {
						return delete parent[lastPart][index];
					} );
					parent[lastPart] = sys.compact( parent[lastPart] );
					return parent[lastPart];
				}
		}
	}
}
function pushin( path, record, setter, newValue ) {
	var context = record;
	var parent = record;
	var lastPart = null;
	var _i;
	var _len;
	var part;
	var keys;

	for ( _i = 0, _len = path.length; _i < _len; _i++ ) {
		part = path[_i];
		lastPart = part;
		parent = context;
		context = context[part];
		if ( sys.isNull( context ) || sys.isUndefined( context ) ) {
			parent[part] = {};
			context = parent[part];
		}
	}

	if ( sys.isEmpty( setter ) || setter === '$set' ) {
		parent[lastPart] = newValue;
		return parent[lastPart];
	} else {
		switch ( setter ) {
			case '$inc':
				/**
				 * Increments a field by the amount you specify. It takes the form
				 * `{ $inc: { field1: amount } }`
				 * @name $inc
				 * @memberOf module:document/probe.updateOperators
				 * @example
				 * var probe = require("document/probe");
				 * probe.update( obj, {'name.last' : 'Owen', 'name.first' : 'LeRoy'},
				 * {$inc : {'password.changes' : 2}} );
				 */

				if ( !sys.isNumber( newValue ) ) {
					newValue = 1;
				}
				if ( sys.isNumber( parent[lastPart] ) ) {
					parent[lastPart] = parent[lastPart] + newValue;
					return parent[lastPart];
				}
				break;
			case '$dec':
				/**
				 * Decrements a field by the amount you specify. It takes the form
				 * `{ $dec: { field1: amount }`
                 * @name $dec
				 * @memberOf module:document/probe.updateOperators
				 * @example
				 *  var probe = require("document/probe");
				 * probe.update( obj, {'name.last' : 'Owen', 'name.first' : 'LeRoy'},
				 * {$dec : {'password.changes' : 2}} );
				 */

				if ( !sys.isNumber( newValue ) ) {
					newValue = 1;
				}
				if ( sys.isNumber( parent[lastPart] ) ) {
					parent[lastPart] = parent[lastPart] - newValue;
					return parent[lastPart];
				}
				break;
			case '$unset':
				/**
				 * Removes the field from the object. It takes the form
				 * `{ $unset: { field1: "" } }`
				 * @name $unset
				 * @memberOf module:document/probe.updateOperators
				 * @example
				 * var probe = require("document/probe");
				 * probe.update( data, {'name.first' : 'Yogi'}, {$unset : {'name.first' : ''}} );
				 */

				return delete parent[lastPart];
			case '$pop':
				/**
				 * The $pop operator removes the first or last element of an array. Pass $pop a value of 1 to remove the last element
				 * in an array and a value of -1 to remove the first element of an array. This will only work on arrays. Syntax:
				 * `{ $pop: { field: 1 } }` or `{ $pop: { field: -1 } }`
				 * @name $pop
				 * @memberOf module:document/probe.updateOperators
				 * @example
				 * var probe = require("document/probe");
				 * // attr is the name of the array field
				 * probe.update( data, {_id : '511d18827da2b88b09000133'}, {$pop : {attr : 1}} );
				 */

				if ( sys.isArray( parent[lastPart] ) ) {
					if ( !sys.isNumber( newValue ) ) {
						newValue = 1;
					}
					if ( newValue === 1 ) {
						return parent[lastPart].pop();
					} else {
						return parent[lastPart].shift();
					}
				}
				break;
			case '$push':
				/**
				 * The $push operator appends a specified value to an array. It looks like this:
				 * `{ $push: { <field>: <value> } }`
				 * @name $push
				 * @memberOf module:document/probe.updateOperators
				 * @example
				 * var probe = require("document/probe");
				 * // attr is the name of the array field
				 * probe.update( data, {_id : '511d18827da2b88b09000133'},
				 * {$push : {attr : {"hand" : "new", "color" : "new"}}} );
				 */

				if ( sys.isArray( parent[lastPart] ) ) {
					return parent[lastPart].push( newValue );
				}
				break;
			case '$pull':
				/**
				 * The $pull operator removes all instances of a value from an existing array. It looks like this:
				 * `{ $pull: { field: <query> } }`
				 * @name $pull
				 * @memberOf module:document/probe.updateOperators
				 * @example
				 * var probe = require("document/probe");
				 * // attr is the name of the array field
				 * probe.update( data, {'email' : 'EWallace.43@fauxprisons.com'},
				 * {$pull : {attr : {"color" : "green"}}} );
				 */

				if ( sys.isArray( parent[lastPart] ) ) {
					keys = exports.findKeys( parent[lastPart], newValue );
					sys.each( keys, function ( val, index ) {
						return delete parent[lastPart][index];
					} );
					parent[lastPart] = sys.compact( parent[lastPart] );
					return parent[lastPart];
				}
		}
	}
}
function pushin ( path , record , setter , newValue ) { var context = record ; var parent = record ; var lastPart = null ; var _i ; var _len ; var part ; var keys ; for ( _i = 0 , _len = path . length ; _i < _len ; _i ++ ) { part = path [ _i ] ; lastPart = part ; parent = context ; context = context [ part ] ; if ( sys . isNull ( context ) || sys . isUndefined ( context ) ) { parent [ part ] = { } ; context = parent [ part ] ; } } if ( sys . isEmpty ( setter ) || setter === '$set' ) { parent [ lastPart ] = newValue ; return parent [ lastPart ] ; } else { switch ( setter ) { case '$inc' : /**
				 * Increments a field by the amount you specify. It takes the form
				 * `{ $inc: { field1: amount } }`
				 * @name $inc
				 * @memberOf module:document/probe.updateOperators
				 * @example
				 * var probe = require("document/probe");
				 * probe.update( obj, {'name.last' : 'Owen', 'name.first' : 'LeRoy'},
				 * {$inc : {'password.changes' : 2}} );
				 */ if ( ! sys . isNumber ( newValue ) ) { newValue = 1 ; } if ( sys . isNumber ( parent [ lastPart ] ) ) { parent [ lastPart ] = parent [ lastPart ] + newValue ; return parent [ lastPart ] ; } break ; case '$dec' : /**
				 * Decrements a field by the amount you specify. It takes the form
				 * `{ $dec: { field1: amount }`
                 * @name $dec
				 * @memberOf module:document/probe.updateOperators
				 * @example
				 *  var probe = require("document/probe");
				 * probe.update( obj, {'name.last' : 'Owen', 'name.first' : 'LeRoy'},
				 * {$dec : {'password.changes' : 2}} );
				 */ if ( ! sys . isNumber ( newValue ) ) { newValue = 1 ; } if ( sys . isNumber ( parent [ lastPart ] ) ) { parent [ lastPart ] = parent [ lastPart ] - newValue ; return parent [ lastPart ] ; } break ; case '$unset' : /**
				 * Removes the field from the object. It takes the form
				 * `{ $unset: { field1: "" } }`
				 * @name $unset
				 * @memberOf module:document/probe.updateOperators
				 * @example
				 * var probe = require("document/probe");
				 * probe.update( data, {'name.first' : 'Yogi'}, {$unset : {'name.first' : ''}} );
				 */ return delete parent [ lastPart ] ; case '$pop' : /**
				 * The $pop operator removes the first or last element of an array. Pass $pop a value of 1 to remove the last element
				 * in an array and a value of -1 to remove the first element of an array. This will only work on arrays. Syntax:
				 * `{ $pop: { field: 1 } }` or `{ $pop: { field: -1 } }`
				 * @name $pop
				 * @memberOf module:document/probe.updateOperators
				 * @example
				 * var probe = require("document/probe");
				 * // attr is the name of the array field
				 * probe.update( data, {_id : '511d18827da2b88b09000133'}, {$pop : {attr : 1}} );
				 */ if ( sys . isArray ( parent [ lastPart ] ) ) { if ( ! sys . isNumber ( newValue ) ) { newValue = 1 ; } if ( newValue === 1 ) { return parent [ lastPart ] . pop ( ) ; } else { return parent [ lastPart ] . shift ( ) ; } } break ; case '$push' : /**
				 * The $push operator appends a specified value to an array. It looks like this:
				 * `{ $push: { <field>: <value> } }`
				 * @name $push
				 * @memberOf module:document/probe.updateOperators
				 * @example
				 * var probe = require("document/probe");
				 * // attr is the name of the array field
				 * probe.update( data, {_id : '511d18827da2b88b09000133'},
				 * {$push : {attr : {"hand" : "new", "color" : "new"}}} );
				 */ if ( sys . isArray ( parent [ lastPart ] ) ) { return parent [ lastPart ] . push ( newValue ) ; } break ; case '$pull' : /**
				 * The $pull operator removes all instances of a value from an existing array. It looks like this:
				 * `{ $pull: { field: <query> } }`
				 * @name $pull
				 * @memberOf module:document/probe.updateOperators
				 * @example
				 * var probe = require("document/probe");
				 * // attr is the name of the array field
				 * probe.update( data, {'email' : 'EWallace.43@fauxprisons.com'},
				 * {$pull : {attr : {"color" : "green"}}} );
				 */ if ( sys . isArray ( parent [ lastPart ] ) ) { keys = exports . findKeys ( parent [ lastPart ] , newValue ) ; sys . each ( keys , function ( val , index ) { return delete parent [ lastPart ] [ index ] ; } ) ; parent [ lastPart ] = sys . compact ( parent [ lastPart ] ) ; return parent [ lastPart ] ; } } } }
This will write the value into a record at the path, creating intervening objects if they don't exist
@private
@param {array} path The split path of the element to work with
@param {object} record The record to reach into
@param {string} setter The set command, defaults to $set
@param {object} newValue The value to write to the, or if the operator is $pull, the query of items to look for
This will write the value into a record at the path creating intervening objects if they don t exist