Comparing version 1.7.3 to 1.7.4
@@ -389,2 +389,24 @@ /** | ||
/** | ||
* Updates the value of the field, only if specified field is greater than the current value of the field | ||
*/ | ||
lastStepModifierFunctions.$max = function (obj, field, value) { | ||
if (typeof obj[field] === 'undefined') { | ||
obj[field] = value; | ||
} else if (value > obj[field]) { | ||
obj[field] = value; | ||
} | ||
}; | ||
/** | ||
* Updates the value of the field, only if specified field is smaller than the current value of the field | ||
*/ | ||
lastStepModifierFunctions.$min = function (obj, field, value) { | ||
if (typeof obj[field] === 'undefined') { | ||
obj[field] = value; | ||
} else if (value < obj[field]) { | ||
obj[field] = value; | ||
} | ||
}; | ||
// Given its name, create the complete modifier function | ||
@@ -391,0 +413,0 @@ function createModifierFunction (modifier) { |
{ | ||
"name": "nedb", | ||
"version": "1.7.3", | ||
"version": "1.7.4", | ||
"author": { | ||
@@ -5,0 +5,0 @@ "name": "Louis Chatriot", |
@@ -435,3 +435,3 @@ <img src="http://i.imgur.com/9O1xHFb.png" style="width: 25%; height: 25%; float: left;"> | ||
* A new document will replace the matched docs | ||
* The modifiers create the fields they need to modify if they don't exist, and you can apply them to subdocs. Available field modifiers are `$set` to change a field's value, `$unset` to delete a field and `$inc` to increment a field's value. To work on arrays, you have `$push`, `$pop`, `$addToSet`, `$pull`, and the special `$each` and `$slice`. See examples below for the syntax. | ||
* The modifiers create the fields they need to modify if they don't exist, and you can apply them to subdocs. Available field modifiers are `$set` to change a field's value, `$unset` to delete a field, `$inc` to increment a field's value and `$min`/`$max` to change field's value, only if provided value is less/greater than current value. To work on arrays, you have `$push`, `$pop`, `$addToSet`, `$pull`, and the special `$each` and `$slice`. See examples below for the syntax. | ||
* `options` is an object with two possible parameters | ||
@@ -544,2 +544,13 @@ * `multi` (defaults to `false`) which allows the modification of several documents if set to true | ||
}); | ||
// $min/$max to update only if provided value is less/greater than current value | ||
// Let's say the database contains this document | ||
// doc = { _id: 'id', name: 'Name', value: 5 } | ||
db.update({ _id: 'id1' }, { $min: { value: 2 } }, {}, function () { | ||
// The document will be updated to { _id: 'id', name: 'Name', value: 2 } | ||
}); | ||
db.update({ _id: 'id1' }, { $min: { value: 8 } }, {}, function () { | ||
// The document will not be modified | ||
}); | ||
``` | ||
@@ -546,0 +557,0 @@ |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1289303
28876
712