![](https://static.wixstatic.com/media/a27d24_f639c8afffee417db9f6f76e11574e5c~mv2.png/v1/fill/w_405,h_548,al_c,q_85,enc_auto/a27d24_f639c8afffee417db9f6f76e11574e5c~mv2.png)
As you can see on the screenshot i'm trying to change the c1 field on the database to another value.But it's really hard to write all the fields each time im trying to update something...
Why can't i use something like:
let toUpdate = {
"_id": itemObj._id,
"c1": change,
};
(Only the field i want to change)?
I read on the API that if i do not include all the fields on the toUpdate, the others will be empty...
Is there another way to just a change one specific field on the database without needing to rewrite all the others?
As you can see, when i console.log the tid, it gives me the correct value, the c14.
But when i print the toUpdate, it gives me a new one "tid" = to the string i wanted.
I want the tid to be treated as variable, so that it takes the c14 value and then replace the c14 with a string.
"c14" = to the string.
I can't get it to get the tid as a variable...it gets it as a string...
I get the itemObj from the current item on the dataset.
tid is just the "c1" or "c2" etc. so that it knows what column to update.
tid gets the value from a backend "whatc".It checks and then returns c1 or c2 or c3 etc. which c1,c2,c3 etc. is column ids on the database.
selectect_hour in this example is "Παρασκευή 10:00-12:00".This is just the value that i want to be added to the column.
if (avail >= 1) { let itemObj = $w("#dynamicDataset").getCurrentItem(); whatc(course_temp).then(product => { tid = product; let toUpdate = Object.assign({}, itemObj, {tid: selected_hour}); wixData.update("Students", toUpdate) }); } else { reset(); }
I have a problem though.
It creates a new column "tid".
I don't want that...i want the text "Παρασκευή 10:00-12:00",which is the "selected_hour" to be added to the "c1",which is the tid var on the code,and this column on the database.
c1 is the column id of the column with the arrow.
if itemObj as an _id, it will be copied to the toUpdate object. If not, it will not be copied. I guess it depends on you if you want to update the item in the database, at which I assume itemObj is the item you read from the DB and as such it has _id property, or if you wanna create a new item at which case itemObj was not read from the database and does not have an _id property.
In the itemObj, should i have a itemObj. _id so that it understands what to replace or it will automaticly get it only with the itemObj?
Hay Maria,
In javascript, you can copy one object into another and override only selected attributes using Object.assign.
In your case, it will look like
let toUpdate = Object.assign({}, itemObj, {"c1": change});