Quick Question - WixData writing to multiple lines

Hello,

How do I stop writing my data to multiple lines?
I am trying to write review data to the database and it is not writing it to the current product instead it is adding two new lines in the collection one for Review Average and another for the How Many Reviews.

Here is my code;


        
 let avgRating = (Math.round(stats.rating * 10 / stats.count) / 10); 
 // Compute the percentage of reviewers that recommend the product.
 let percentRecommended = Math.round(stats.recommended / stats.count * 100); 
 // Get the ratings element.
 let ratings = $w('#generalRatings');
 let ratings2 = $w('#ratingsDisplay1');
 // Set the ratings element's average rating to the value calculated above. 
        ratings.rating = avgRating;
        ratings2.rating = avgRating;
        wixData.insert("reviews", {"reviewAvg": avgRating});
 // Set the ratings element's number of ratings to the count value from the statistics data.
        ratings.numRatings = stats.count;
        ratings2.numRatings = stats.count;
 // Write review number to database
        wixData.insert("reviews", {"numberofReviews": stats.count});

Here is my result;


How do I get this to be on the same line as the Product?

Thanks!

You may want to UPDATE instead of INSERT!
https://www.wix.com/velo/reference/wix-data/update

Or you probably also could use …
https://www.wix.com/velo/reference/wix-data/save

And you make an failure. You write in two separate sequences, instead of just one insert-sequence.

Understood your problem! (So if you want to —> INSERT at once…)


 let avgRating = (Math.round(stats.rating * 10 / stats.count) / 10); 
 let percentRecommended = Math.round(stats.recommended / stats.count * 100); 
 let ratings = $w('#generalRatings');
 let ratings2 = $w('#ratingsDisplay1');
     ratings.rating = avgRating;
     ratings2.rating = avgRating;
     ratings.numRatings = stats.count;
     ratings2.numRatings = stats.count;

 let toInsert = {
    "reviewAvg": avgRating, 
    "numberofReviews": stats.count
 }

 wixData.insert("reviews", toInsert);

@russian-dima That’s it!!! Thank you so much! This is exactly what I needed. I really appreciate it.