# Array Field Operations API

> Perform push, pull, pop, and other array operations on document fields—simplify array data handling via API.

Source: https://docs.apimaker.dev/v1/examples/sys/db/gen/arrayOperationsGen.html

<!-- --8<-- [start:body] -->

`g.sys.db.gen.arrayOperationsGen` calls the [array operations generated API](/v1/docs/apis-all/generated-apis/auto-generated-array-operations-api.html) from your code : no schema, the data as it is in the table.

### Schema-less Array Operations API 

```typescript title="Array operations" linenums="1"
await g.sys.db.gen.arrayOperationsGen({
    instance: 'INSTANCE_NAME',
    database: 'DATABASE_NAME',
    collection: 'COLLECTION_NAME',
    find: {
        "id": 1
    },
    operations: [
        {
            operation: "push",
            path: "attributes.color",
            dataToPush: [
                "YELLOW",
                "SKY_BLUE"
            ]
        }
    ]
});
```

```typescript title="Array operations headers support" linenums="1"
await g.sys.db.gen.arrayOperationsGen({
    // ...
    headers: {
        "x-am-authorization": "TOKEN"
    }
});
```

## Multi-tenant
- `instance: "crm::acme"` works on the database of the tenant `acme` of the [multi-tenant](/v1/docs/features/multi-tenant.html) instance `crm`.
- With `instance: "crm"`, the call works on the database of the tenant of the request: a custom API called with the [x-am-tenant-username](/v1/docs/apis-all/header/requestHeader.html#x-am-tenant-username) header passes it on to the APIs it calls. A request without a tenant works on the structure database.

```typescript title="Array operations on a customer of the tenant acme" linenums="1"
let arrayOperations = await g.sys.db.gen.arrayOperationsGen({
instance: "crm::acme", database: "crm", collection: "customers",
    find: {
        "customer_id": 1
    },
    operations: [
        {
            operation: "push",
            path: "tags",
            dataToPush: ["vip"]
        }
    ]
});
```

<!-- --8<-- [end:body] -->

## Related

- [Array operations generated API](/v1/docs/apis-all/generated-apis/auto-generated-array-operations-api.html) · [Schema API from code](/v1/examples/sys/db/arrayOperations.html) · [The global object g](/v1/docs/pre-defined-terms/global-object-g.html)
