Skip to content

Remove by query

Structure

Remove by query
1
2
3
4
5
6
7
8
let updateById = await g.sys.db.gen.removeByQueryGen({
    instance: "INSTANCE_NAME",
    database: "DATABASE_NAME",
    collection: "COLLECTION_NAME",
    find: {
        "city_name": "LONDON"
    }
});

Simple removeByQuery

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

$lt removeByQuery

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

$lte removeByQuery

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

$gt removeByQuery

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

$gte removeByQuery

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

$eq removeByQuery

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

$ne removeByQuery

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

$not removeByQuery

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

$and removeByQuery

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

$or removeByQuery

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

$in removeByQuery

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

$nin removeByQuery

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

$like removeByQuery

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

MongoDB $in operator in nested find

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

MongoDB $or operator in nested find

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