BulkUpdate entire database

Hi,

I understand that BulkUpdate requires array of the field ids

but I want to BulkUpdate one of the field for all rows( the entire database)
How can I get all ids and bulkupdate in this case?

this is the code that I have:

export function bulkAddButton_click(event) {
//I have a field where it stores "quantity"; consists of number but field type is text

//clicking this bulkAddButton works to add "+1" to the "quantity field" for all rows (entire database)

wixData.query("Management") 
.eq("quantity")
.find()
.then((result)=>{
let items = result.items
let item = items[0]
let quantity = item.quantity //this seems to be only ONE ROW

let quantityPlusOne = parseFloat(quantity) + 1

let quantityString = quantityPlusOne.toString()

//I am stuck 
//I can't get value of quantity field for all rows
//I can't get the whole database IDs
//and I don't know how to BulkUpdate without the ID

console.log(??)
})

Hope you get the idea! Thanks in advance!!!

1 Like

Hi Haydi,

It seems that you are expecting the query to return just the quantity field since you are specifying that with the eq function. However, the eq function i s meant to be a function that limits or filters the results.

In fact, you want to return the values of all the fields in the collection row, so that you can make sure you don’t lose the values of the other fields when you use BulkUpdate .

Here’s an approach:

export function bulkAddButton_click(event) {
wixData.query("Management")
.limit(1000)
.find()
.then((result)=>{
    let items = result.items
    // create array to create all of individual record objects.     
    let bulkArray = [];
    let item = {};
    let quantityPlusOne = 0;
    for (var i = 0; i < items.length; i++) {
        item = items[i];
        quantityPlusOne = parseFloat(item.quantity) + 1;
        item.quantity = quantityPlusOne.toString();
        // add the revised record object that includes the new quantity value 
        // and all of the current values of the other fields (including _id)    
        // to the array.
        bulkArray.push(item);
    }
     wixData.bulkUpdate("RetreatPmts", bulkArray)
      .then ((bulkResult) => {
          console.log(bulkResult);
     } )
      .catch( (err) => {
          console.log(err);
      } );
});

}