Keep a single updated line in DB

Hi All,
I have setup a remote update to a DB in Wix and it works great.
I have two minor issues:

  1. Each remote update is inserting a new line to the DB, while I only need an updated single entry.
  2. if I am sending a list of parameters, if any parameter is missing (intentionally) I get an empty value (again as in section 1, in another entry)

Is there a way to only have a single entry in the DB, and be able to update it with some (and not all) parameters while keeping the existing ones as is?

the current http-functions.js file:

import {ok, created, badRequest, notFound, serverError, response} from ‘wix-http-functions’;
import wixData from ‘wix-data’;
export function post_tabledata(request) {
let options = {
“headers”: {
“Content-Type”: “application/json”
return request.body.json()
.then( (body) => {
return createLine(body, options);
. catch ( (error) => {
options.body = {
“error”: error
return serverError(options);
function createLine(body, options) {
let dataInsert = {
“c1FirstLine”: body.c1FirstLine, //Challenge 1 First Line
“c2FirstLine”: body.c2FirstLine, //Challenge 2 First Line
“c3FirstLine”: body.c3FirstLine, //Challenge 3 First Line
“c1SecondLine”: body.c1SecondLine, //Challenge 1 Second Line
“c2SecondLine”: body.c2SecondLine, //Challenge 2 Second Line
“c3SecondLine”: body.c3SecondLine, //Challenge 3 Second Line
“c1ThirdLine”: body.c1ThirdLine, //Challenge 1 Third Line
“c2ThirdLine”: body.c2ThirdLine, //Challenge 2 Third Line
“c3ThirdLine”: body.c3ThirdLine, //Challenge 3 Third Line
“button1”: body.button1, //Challenge 1 button to OfficeGuy payment page
“button2”: body.button2, //Challenge 2 button to OfficeGuy payment page
“button3”: body.button3 //Challenge 3 button to OfficeGuy payment page
return wixData.insert(‘ChallengeDates’, dataInsert)
.then( (result) => {
let item = result;
options.body = {
“status”: 200,
“response”: item
return created(options);

Thanks a lot!

Depending on your requirements, you should use either update() or save() for updating a collection item.

I have tried that but with no success, can you please be more specific?

You are using wixData.insert() (which inserts a new item into the database) whereas your goal is to update an item.

You should be using wixData.update() but for that you need to get the id of the item you are trying to update.

In your current scenario, you should find a way to include the id of the item in the database as a parameter or in the request body. Then query the item from the database and finally update the fields using wixData.update()

Read the docs:

1 Like

Yup …what he said :top: