Skip to content

Support for MongoDB $push operator #363

@rafaelkaufmann

Description

@rafaelkaufmann

I've noticed orm currently only supports the $set operator for MongoDB databases. A simple change to the update method, such as proposed below, would allow other operators such as $push, while maintaining implicit use of $set.

Driver.prototype.update = function (table, changes, conditions, cb) {

    convertToDB(changes, this.config.timezone);
    convertToDB(conditions, this.config.timezone);

    var operator = '$set';
    var changesKeys = Object.keys(changes);
    if (changesKeys[0][0] == '$') {
        operator = changesKeys[0];
        changes = changes[operator];
    }

    var operation = {};
    operation[operator] = changes;

    return this.db.collection(table).update(
        conditions,
        operation,
        {
            safe   : true,
            upsert : true
        },
        cb
    );
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions