Skip to content

Replace by id

Structure

Replace by id
let replaceById = await g.sys.db.gen.replaceByIdGen({
    instance: "INSTANCE_NAME",
    database: "DATABASE_NAME",
    collection: "COLLECTION_NAME",
    id: 45855,
    primaryKey: "pincode",
    updateData: {
        "first_name": "Elonn",
        "last_name": "Mask"
    },
    returnOriginal: true,
    select: "COLUMN_NAMES",
    upsert: false
});

Simple replaceById

Replace By Id
1
2
3
4
5
6
7
8
9
let replaceById = await g.sys.db.gen.replaceByIdGen({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    id: 1,
    updateData: {
        "first_name": "MALLORY"
    }
});

replaceById primaryKey override

Replace By Id primarykey override
let replaceById = await g.sys.db.gen.replaceByIdGen({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    id: "Bob",
    primaryKey: "first_name",    
    updateData: {
        "first_name": "MALLORY"
    }
});

replaceById [header]

Replace By Id header
let replaceById = await g.sys.db.gen.replaceByIdGen({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    id: "Bob",
    primaryKey: "first_name",    
    updateData: {
        "first_name": "MALLORY"
    },
    headers: {
        "x-am-response-case": "capitalCase"
    }
});

replaceById [select]

Replace By Id select
let replaceById = await g.sys.db.gen.replaceByIdGen({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    id: "Bob",
    primaryKey: "first_name",    
    updateData: {
        "first_name": "MALLORY"
    },
    select: "first_name,last_name"
});

replaceById [upsert]

Replace By Id upsert
let replaceById = await g.sys.db.gen.replaceByIdGen({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    id: "Bob",
    primaryKey: "first_name",    
    updateData: {
        "first_name": "MALLORY"
    },
    select: "first_name,last_name",
    upsert: true
});

replaceById [returnDocument]

Replace By Id returnDocument
let replaceById = await g.sys.db.gen.replaceByIdGen({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    id: "Bob",
    primaryKey: "first_name",    
    updateData: {
        "first_name": "MALLORY"
    },
    select: "first_name,last_name",
    returnDocument: true
});