Skip to content

Count

Simple get count

Simple get count
1
2
3
4
5
let count = await g.sys.db.count({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
});

get count [headers]

get count with headers
1
2
3
4
5
6
7
8
let count = await g.sys.db.count({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    headers: {
        "x-am-response-case": "capitalCase", // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
    },
});

get count [find]

Simple find
1
2
3
4
5
6
7
8
let count = await g.sys.db.count({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    find:{
        "first_name": "Bob"
    }
});

$gt

$gt
let count = await g.sys.db.count({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    find: {
        "customer_id": {
            "$gt": 4
        }
    }
});

$gte

$gte
let count = await g.sys.db.count({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    find: {
        "customer_id": {
            "$gte": 4
        }
    }
});

$lt

$lt
let count = await g.sys.db.count({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    find: {
        "customer_id": {
            "$lt": 4
        }
    }
});

$lte

$lte
let count = await g.sys.db.count({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    find: {
        "customer_id": {
            "$lte": 4
        }
    }
});

$eq

$eq
let count = await g.sys.db.count({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    find: {
        "first_name": {
            "$eq": "Bob"
        }
    }
});

$ne

$ne
let count = await g.sys.db.count({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    find: {
        "first_name": {
            "$ne": "Bob"
        }
    }
});

$in

$in
let count = await g.sys.db.count({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    find: {
        "customer_id": {
            "$in": [1, 2]
        }
    }
});

$nin

$nin
let count = await g.sys.db.count({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    find: {
        "customer_id": {
            "$nin": [1, 2]
        }
    }
});

$and

$and
let count = await g.sys.db.count({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    find: {
        "$and": [
            {
                "employee_Details.emp_Id": 1
            },
            {
                "city": "Baroda"
            }
        ]
    }
});

$or

$or
let count = await g.sys.db.count({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    find: {
        "$or": [
            {
                "state": "Gujarat"
            },
            {
                "city": "Baroda"
            }
        ]
    }
});

$like

$like
let count = await g.sys.db.count({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    find: {
        "first_name": {
            "$like": "%Mall%"
        }
    }
});

floating value support

floating value support
let count = await g.sys.db.count({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    find: {
        "customer_id":{
            "$gt": 2.2
        }
    }
});

Structure

Count method
let count = await g.sys.db.count({
    instance: "INSTANCE_NAME",
    database: "DATABASE_NAME",
    collection: "COLLECTION_NAME",
    find: {
        "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",
    },
});