Skip to content

Query for get data

Simple query

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

query [headers]

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

query [select]

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

query [limit]

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

query [skip]

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

query [sort]

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

query [deep]

query deep
let query = await g.sys.db.query({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    find:{
        "first_name": "Bob"
    },
    deep: [
        {
            s_key: "customer_id",
            t_instance: "mysql",
            t_db: "inventory",
            t_col: "products",
            t_key: "owner_id",
        }
    ],
});

$lt [less than] query

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

$lte [less than equal] query

less than equal query
let query = await g.sys.db.query({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    find: {
        customer_id: {
            "$lte": 2
        }
    }
});

$gt [greater than] query

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

$gte [greater than equal] query

greater than equal query
let query = await g.sys.db.query({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    find: {
        customer_id: {
            "$gte": 2
        }
    }
});

$eq [equal to] query

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

$ne [not equal to] query

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

$not [not] query

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

$and [and] query

$and query
let query = await g.sys.db.query({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    find: {
        "$and": [
            {
                "customer_id": 2
            },
            {
                "pincode": 7171
            }
        ]
    }
});

Find-join example

find join $and query
let query = await g.sys.db.query({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    find: {
        "$and": [
            {
                "first_name.customer_id.shipping_id": 2
            },
            {
                "first_name.customer_id.order_id": 58
            }
        ]
    }
});

$or [or] query

$or query
let query = await g.sys.db.query({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    find: {
        "$or": [
            {
                "customer_id": 2
            },
            {
                "pincode": 7171
            }
        ]
    }
});

Find-join example

find join $or query
let query = await g.sys.db.query({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    find: {
        "$or": [
            {
                "first_name.customer_id.shipping_id": 2
            },
            {
                "first_name.customer_id.order_id": 58
            }
        ]
    }
});

$in [in] query

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

$nin [not in] query

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

$like [like] query

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

MongoDB $in operator in nested find

$in operator in nested find
let query = await g.sys.db.query({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    find: {
        "eventListeners.versions.name": {
            "$in": [
                "Original",
                "1"
            ]
        }
    }
});

MongoDB $nin operator in nested find

$nin operator in nested find
let query = await g.sys.db.query({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    find: {
        "eventListeners.versions.name": {
            "$nin": [
                "Original",
                "1"
            ]
        }
    }
});

MongoDB $and operator in nested find

$and operator in nested find
let query = await g.sys.db.query({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    find: {
        "$and": [
            {
                "eventListeners.versions.name": "Original"
            },
            {
                "eventListeners.versions.version": "-1"
            }
        ]
    }
});

MongoDB $or operator in nested find

$or operator in nested find
let query = await g.sys.db.query({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    find: {
        "$or": [
            {
                "eventListeners.versions.name": "Original"
            },
            {
                "eventListeners.versions.version": "-1"
            }
        ]
    }
});

Structure

query with all params
let query = await g.sys.db.query({
    instance: "INSTANCE_NAME",
    database: "DATABASE_NAME",
    collection: "COLLECTION_NAME",
    find: {
        "COLUMN_NAME": "VALUE"
    },
    limit: 10,
    select: "COMMA_SEPARATED_COLUMN_NAMES",
    deep: [
        {
            s_key: "SOURCE_COLLECTION_COLUMN_NAME",
            t_instance: "TARGET_INSTANCE_NAME",
            t_db: "TARGET_DATABASE_NAME",
            t_col: "TARGET_COLLECTION_NAME",
            t_key: "TARGET_COLLECTION_COLUMN_NAME",
            find: {
                "COLUMN_NAME": "COLUMN_VALUE"
            },
            isMultiple: true,
            limit: 10,
            select: "COMMA_SEPARATED_COLUMN_NAMES",
            skip: 2,
            sort: "COLUMN_NAME",
        }
    ],
    skip: 1,
    sort: "COLUMN_NAME",
    groupBy: "COLUMN_NAME",
    getTotalCount: true,
    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",
    },
}, true);