src/query.js
function updateObject(entities, descriptor) {

    if (!entities) {
        return entities;
    }

    let result = Array.isArray(entities) ? entities : [entities];

    if (!isUpdateDescriptor(descriptor)) {
        return descriptor && typeof descriptor === 'object'
            ? [util.copyMetaProperties(descriptor, result[0])]
            : result;
    }

    // get updater operations
    let operations = Object.keys(descriptor)
        .map(opType => ({name: opType, transformation: UPDATE_OPS[opType]}))
        .filter(op => op.transformation);

    for (let operator of operations) {
        result = mutate(result, descriptor[operator.name], operator.transformation);
    }

    return result;
}
function updateObject(entities, descriptor) {

    if (!entities) {
        return entities;
    }

    let result = Array.isArray(entities) ? entities : [entities];

    if (!isUpdateDescriptor(descriptor)) {
        return descriptor && typeof descriptor === 'object'
            ? [util.copyMetaProperties(descriptor, result[0])]
            : result;
    }

    // get updater operations
    let operations = Object.keys(descriptor)
        .map(opType => ({name: opType, transformation: UPDATE_OPS[opType]}))
        .filter(op => op.transformation);

    for (let operator of operations) {
        result = mutate(result, descriptor[operator.name], operator.transformation);
    }

    return result;
}
function updateObject ( entities , descriptor ) { if ( ! entities ) { return entities ; } let result = Array . isArray ( entities ) ? entities : [ entities ] ; if ( ! isUpdateDescriptor ( descriptor ) ) { return descriptor && typeof descriptor === 'object' ? [ util . copyMetaProperties ( descriptor , result [ 0 ] ) ] : result ; } // get updater operations let operations = Object . keys ( descriptor ) . map ( opType => ( { name : opType , transformation : UPDATE_OPS [ opType ] } ) ) . filter ( op => op . transformation ) ; for ( let operator of operations ) { result = mutate ( result , descriptor [ operator . name ] , operator . transformation ) ; } return result ; }
Updates the object based on the MongoDB specification. It wont mutate the original object

@param {object} entities Original object
@param {object} descriptor Update description
@returns {*}
Updates the object based on the MongoDB specification . It wont mutate the original object