wixData.update - Invalid update. Updated object must have a string property

Why do I get this error? Why the update only works with strings? I also have fields of numbers that needs to be updated, what if I have images that needs to be updated? How can I update them only with code?

product = await $w('#productPage').getProduct();
let productId = product._id

wixData.query("review-stats").eq("productId", product._id).find().then(async (result) => {
    if (result.items.length > 0) {
        let oldItem = result.items[0];

        let item = {
            count: oldItem.count + 1,
            rating: oldItem.rating + userRating,
            recommended: oldItem.recommended + newRecom,
            productId: product._id,
            productID: product._id
        }
        await wixData.update("review-stats", item)
    }
})

How can I update these fields?

You must have _id key inside the object if you want to update an existing item (otherwise it won’t know which item to update).
If you want to insert a new item then use wixData.insert() instead

I’m trying to update the product ID of the product in the database, the key _id is a system key inside the Products collection, and it defiantly does exist.

@ahmadnasriya
See in red:

let item = {
            _id: oldItem._id,
            count: oldItem.count + 1,
            rating: oldItem.rating + userRating,
            recommended: oldItem.recommended + newRecom,
            productId: product._id,
            productID: product._id
        }

and if you want to keep the existing values and only update these ones then:

product = await $w('#productPage').getProduct();
let productId = product._id;
wixData.query("review-stats").eq("productId", product._id).find().then(async (result) => {
    if (result.items.length > 0) {
        let item = result.items[0];
            item.count += 1;
            item.rating += userRating;
            item.recommended += newRecom;
            item.productId = product._id;
            item.productID = product._id;
        await wixData.update("review-stats", item);
    }
})

FIXED

@jonatandor35 Thanks a lot :blush: , I’ll try this out and hopefully it will work

Thanks @jonatandor35 , it worked like a charm :slightly_smiling_face::blush:
You’re awesome man!

@ahmadnasriya you’re welcome :slight_smile: