Skip to content

Update many

Simple update-many

Update many
let updateMany = await g.sys.db.updateMany({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    find: {
        "first_name": "Alice"
    },
    updateData: {
        "first_name": "MALLORY"
    }
});

update-many with header

Update many with header
let updateMany = await g.sys.db.updateMany({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    find: {
        "first_name": "Alice"
    },
    updateData: {
        "first_name": "MALLORY"
    },
    headers: {
        "x-am-response-case": "capitalCase", // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
    },
});

$in update-many

$in Update many
let updateMany = await g.sys.db.updateMany({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    find: {
        "customer_id": {
            "$in": [2, 3]
        }
    },
    updateData: {
        "first_name": "MALLORY"
    }
});

$nin update-many

$nin Update many
let updateMany = await g.sys.db.updateMany({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    find: {
        "customer_id": {
            "$nin": [2, 3]
        }
    },
    updateData: {
        "first_name": "MALLORY"
    }
});

$and update-many

$and Update many
let updateMany = await g.sys.db.updateMany({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    find: {
        $and: [
            {
                "first_name": "Alice"
            },
            {
                "isActive": 1
            }
        ]
    },
    updateData: {
        "first_name": "MALLORY"
    }
});

$or update-many

$or Update many
let updateMany = await g.sys.db.updateMany({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    find: {
        $or: [
            {
                "first_name": "Alice"
            },
            {
                "isActive": 1
            }
        ]
    },
    updateData: {
        "first_name": "MALLORY"
    }
});

$eq update-many

$eq Update many
let updateMany = await g.sys.db.updateMany({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    find: {
        "customer_id": {
            "$eq": 2
        }
    },
    updateData: {
        "first_name": "MALLORY"
    }
});

$gt update-many

$gt Update many
let updateMany = await g.sys.db.updateMany({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    find: {
        "customer_id": {
            "$gt": 2
        }
    },
    updateData: {
        "first_name": "MALLORY"
    }
});

$gte update-many

$gte Update many
let updateMany = await g.sys.db.updateMany({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    find: {
        "customer_id": {
            "$gte": 2
        }
    },
    updateData: {
        "first_name": "MALLORY"
    }
});

$lt update-many

$lt Update many
let updateMany = await g.sys.db.updateMany({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    find: {
        "customer_id": {
            "$lt": 2
        }
    },
    updateData: {
        "first_name": "MALLORY"
    }
});

$lte update-many

$lte Update many
let updateMany = await g.sys.db.updateMany({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    find: {
        "customer_id": {
            "$lte": 2
        }
    },
    updateData: {
        "first_name": "MALLORY"
    }
});

[mongoDB] update-many

$mongoDB Update many
let updateMany = await g.sys.db.updateMany({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    find: {
        "customer_id": 2,
        "ages.birth_year": "1889"
    },
    updateData: {
        "ages.$.age": "35"
    }
});

[MongoDB] $elemMatch, $gte, $lte update-many

$elemMatch, $gte, $lte Update many
let updateMany = await g.sys.db.updateMany({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    find: {
        "customer_id": 2,
        "ages": {
            "$elemMatch": {
                "age": {
                    "$gte": 30
                },
                "birth_year": {
                    "$lte": 1900
                }
            }
        }
    },
    updateData: {
        "first_name": "MALLORY"
    }
});

Structure

Update many
let updateMany = await g.sys.db.updateMany({
    instance: "INSTANCE_NAME",
    database: "DATABASE_NAME",
    collection: "COLLECTION_NAME",
    find: {
        "COLUMN_NAME": "VALUE",
    },
    updateData: {
        "COLUMN_NAME": "VALUE",
    },
    headers: {
        "x-am-response-case": "capitalCase", // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
        "x-am-response-object-type": "make_flat", // no_action | make_flat
        "x-am-meta": "true", // true, false
        "x-am-secret": "PROVIDE_SECRET_ID",
        "x-am-internationalization": "USER_I18N_ID",
        "x-am-run-in-sandbox": "2",
        "x-am-content-type-response": "text/xml", // application/json | text/xml | text/yaml | text/plain | text/html | application/octet-stream
        "x-am-cache-control": "reset_cache", // no_action | reset_cache
        "x-am-get-encrypted-data": "get_only_encryption", // no_encryption | get_only_encryption | get_data_and_encryption
        "x-am-sandbox-timeout": "13000",
        "x-no-compression": "true", // true | false
        "x-am-encrypted-payload": "true", // user will send 'true', when payload is encrypted for transfer
        // Authorization headers
        "x-am-authorization": "AUTHORIZATION_TOKEN",
        "x-am-user-authorization": "API_USER_TOKEN",
        "x-aws-authorization": "AWS_TOKEN",
        "x-google-authorization": "GOOGLE_TOKEN",
        "x-azure-authorization": "AZURE_TOKEN",
    },
});