Skip to main content

Upsert and conflicts

Use the upsert: true option to handle conflicts by updating existing records instead of creating a duplicate. When you enable upsert, you must provide conflictKeys to tell MantaHQ which fields to use to identify a match (for example, a unique ID or an email address).

Single conflict keys

If you are checking for a conflict based on a single field, you only need to provide the field name in the conflictKeys array.

TypeScript
await manta.createRecords({
table: "products",
data: [
{ product_id: "P-1", name: "Laptop" },
{ product_id: "P-2", name: "Phone" },
],
options: {
upsert: true,
conflictKeys: ["product_id"],
},
});

Multiple conflict keys

When using multiple keys to identify a conflict, use conflictKeysLogic to define how the match should be evaluated.

  • and: A conflict is triggered only if all specified keys match an existing record.
  • or: A conflict is triggered if any of the specified keys match an existing record.
TypeScript
await manta.createRecords({
table: "products",
data: [
{ product_id: "P-1", name: "Laptop" },
{ product_id: "P-2", name: "Phone" },
],
options: {
upsert: true,
conflictKeys: ["product_id", "name"],
conflictKeysLogic: "and",
},
});