diff --git a/lib/model.js b/lib/model.js index 622977d..2f7f1e4 100644 --- a/lib/model.js +++ b/lib/model.js @@ -9,6 +9,7 @@ var dateToJSON = function () { return { $$date: this.getTime() }; } , util = require('util') , _ = require('underscore') , modifierFunctions = {} + , lastStepModifierFunctions = {} , comparisonFunctions = {} , logicalOperators = {} ; @@ -213,6 +214,22 @@ function compareThings (a, b) { // Updating documents // ============================================================== + +lastStepModifierFunctions.$set = function (obj, field, value) { + obj[field] = value; +}; + +function findLastModificationStep (modifier, obj, field, value) { + var fieldParts = typeof field === 'string' ? field.split('.') : field; + + if (fieldParts.length === 1) { + lastStepModifierFunctions[modifier](obj, field, value); + } else { + obj[fieldParts[0]] = obj[fieldParts[0]] || {}; + modifierFunctions[modifier](obj[fieldParts[0]], fieldParts.slice(1), value); + } +} + /** * Set field to value in a model * Create it if it doesn't exist