Skip to content

Query for get data

Structure

Query method
let query = await g.sys.db.gen.queryGen({
    instance: "INSTANCE_NAME",
    database: "DATABASE_NAME",
    collection: "COLLECTION_NAME",
    find: {
        "pincode": 100050
    },
    limit: 1,
    select: "COLUMN_NAMES",
    deep: [{
        s_key: "SOURCE_COLLECTION_COLUMN_NAME",
        t_key: "TARGET_COLLECTION_COLUMN_NAME",
        t_col: "TARGET_COLLECTION_NAME",
        select: "COLUMN_NAMES"
    }],
    skip: 1,
    sort: "COLUMN_NAME",
    groupBy: "COLUMN_NAME"
});

Simple query

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

Simple [headers]

headers
let query = await g.sys.db.gen.queryGen({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    find:{
        "first_name": "Bob"
    },
    headers: {
        "x-am-response-case": "capitalCase"
    }
});

Simple [select]

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

Simple [limit]

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

Simple [skip]

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

Simple [sort]

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

Simple [deep]

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

$lt query

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

$lte query

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

$gt query

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

$gte query

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

$eq query

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

$ne query

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

$not query

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

$and query

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

$or query

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

$in query

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

$nin query

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

$like query

$like query
let query = await g.sys.db.gen.queryGen({
    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.gen.queryGen({
    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.gen.queryGen({
    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.gen.queryGen({
    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.gen.queryGen({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    find: {
        "$or": [
            {
                "eventListeners.versions.name": "Original"
            },
            {
                "eventListeners.versions.version": "-1"
            }
        ]
    }
});