Constructor
new updateOperators()
- Source:
These are the supported update operators
Members
(static) $dec
- Source:
Decrements a field by the amount you specify. It takes the form
{ $dec: { field1: amount }
Example
var probe = require("documents/probe");
probe.update( obj, {'name.last' : 'Owen', 'name.first' : 'LeRoy'},
{$dec : {'password.changes' : 2}} );
(static) $inc
- Source:
Increments a field by the amount you specify. It takes the form
{ $inc: { field1: amount } }
Example
var probe = require("documents/probe");
probe.update( obj, {'name.last' : 'Owen', 'name.first' : 'LeRoy'},
{$inc : {'password.changes' : 2}} );
(static) $pop
- Source:
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 } }
Example
var probe = require("documents/probe");
// attr is the name of the array field
probe.update( data, {_id : '511d18827da2b88b09000133'}, {$pop : {attr : 1}} );
(static) $pull
- Source:
The $pull operator removes all instances of a value from an existing array. It looks like this:
{ $pull: { field: <query> } }
Example
var probe = require("documents/probe");
// attr is the name of the array field
probe.update( data, {'email' : 'EWallace.43@fauxprisons.com'},
{$pull : {attr : {"color" : "green"}}} );
(static) $push
- Source:
The $push operator appends a specified value to an array. It looks like this:
{ $push: { <field>: <value> } }
Example
var probe = require("documents/probe");
// attr is the name of the array field
probe.update( data, {_id : '511d18827da2b88b09000133'},
{$push : {attr : {"hand" : "new", "color" : "new"}}} );
(static) $unset
- Source:
Removes the field from the object. It takes the form
{ $unset: { field1: "" } }
Example
var probe = require("documents/probe");
probe.update( data, {'name.first' : 'Yogi'}, {$unset : {'name.first' : ''}} );