Skip to content
This page View Markdown Open in ChatGPT Open in Claude

Array operations

g.sys.db.gen.arrayOperationsGen calls the array operations generated API from your code : no schema, the data as it is in the table.

Schema-less Array Operations API

Array operations
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"
            ]
        }
    ]
});
Array operations headers support
1
2
3
4
5
6
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 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 header passes it on to the APIs it calls. A request without a tenant works on the structure database.
Array operations on a customer of the tenant acme
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"]
        }
    ]
});