Skip to content

Array operations

Array operation [push]

Array operation push
await g.sys.db.arrayOperations({
    instance: "mongodb",
    database: "inventory",
    collection: "customers",
    find: {
        "customer_id": 1
    },
    operations: [
        {
            operation: "push",
            path: "attributes.color",
            dataToPush: [
                "YELLOW",
                "SKY_BLUE"
            ]
        }
    ]
});

Array operation [pull]

Array operation pull
await g.sys.db.arrayOperations({
    instance: "mongodb",
    database: "inventory",
    collection: "customers",
    find: {
        "customer_id": 1
    },
    operations: [
        {
            operation: "pull",
            path: "ages",
            queryToRemove: {
                "age": 2,
                "birth_year": 1989,
                "country_id": 1
            }
        }
    ]
});

Array operation [pullAll]

Array operation pullAll
await g.sys.db.arrayOperations({
    instance: "mongodb",
    database: "inventory",
    collection: "customers",
    find: {
        "customer_id": 1
    },
    operations: [
        {
            operation: "pullAll",
            path: "attributes.size",
            dataToPull: [
                3.5
            ]
        }
    ]
});

Array operation [pop]

Array operation pop
await g.sys.db.arrayOperations({
    instance: "mongodb",
    database: "inventory",
    collection: "customers",
    find: {
        "customer_id": 1
    },
    operations: [
        {
            operation: "pop",
            path: "attributes.color",
            direction: 1
        }
    ]
});

Array operation [set]

Array operation set
await g.sys.db.arrayOperations({
    instance: "mongodb",
    database: "inventory",
    collection: "customers",
    find: {
        "customer_id": 1
    },
    operations: [
        {
            operation: "set",
            dataToSet: {
                'ages.birth_year': 1890,
            },
            arrayFilters: [
                {
                    'item.age': 4,
                },
            ],
        }
    ]
});

Array operation [addToSet]

Array operation addToSet
await g.sys.db.arrayOperations({
    instance: "mongodb",
    database: "inventory",
    collection: "customers",
    find: {
        "customer_id": 1
    },
    operations: [
        {
            operation: "addToSet",
            dataToSet: {
                'ages.birth_year': 1890,
            },
            arrayFilters: [
                {
                    'item.age': 4,
                },
            ],
        }
    ]
});

Structure

Array operations
await g.sys.db.arrayOperations({
    instance: "INSTANCE_NAME",
    database: "DATABASE_NAME",
    collection: "COLLECTION_NAME",
    find: {
        "customer_id": 1
    },
    operations: [
        {
            operation: "push", // push | addToSet | pull | pullAll | pop | set
            path: "attributes.color",
            dataToPush: [
                "YELLOW",
                "SKY_BLUE"
            ]
        },
        {
            operation: "pull", // push | addToSet | pull | pullAll | pop | set
            path: "attributes.color",
            dataToPull: [
                "SKY_BLUE"
            ]
        }
    ],
    select: "COMMA_SEPARATED_COLUMN_NAMES",
    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",
    },
});