I am trying to use bulk update function in backend https://www.wix.com/corvid/reference/wix-data.html#bulkUpdate . The documentation looks like is has to split the array of elements e.g. toUpdate[1] and toUpdate[2] rather than toUpdate .
wixData.bulkUpdate("myCollection", [toUpdate1, toUpdate2], options)
Is their a way to use bulkUpdate with just the array?
lee1
December 7, 2019, 1:02pm
2
[toUpdate1, toUpdate2] is just an array. So yes, you can pass your existing array if you already have one, rather than constructing one as they do in the documentation.
I have been trying to make this work for days, I have an array but I am not getting anything. Any tips would be greatly appreciated!
export function ythHmsGenerate() {
wixData.query("IndividualJudgesPlacings")
.eq("ythHms", true)
.eq("owner", user.id)
.limit(100)
.find()
.then((results) => {
console.log(results)
let items = results.items;
let titles = items.map(item => item.title);
console.log("here are titles" + titles)
wixData.query("NationalChampionshipRankings")
.not(
wixData.query("NationalChampionshipRankings")
.hasSome("title", titles)
)
.eq("youthHms", true)
.limit(100)
.find()
.then((results) => {
console.log(results)
let items2 = results.items
let needsToBeInserted = items2.map(item => [item.title, item.youthHms, item.youthEq, item.youthSms])
shows in console as array----> console.log(needsToBeInserted)
wixData.bulkInsert("IndividualJudgesPlacings", [needsToBeInserted])
//console.log("done maybe");
//console.log ("Bulk Insert Results" + results)
// $w("#repeater1").expand();
// .catch((err) => {
// let errorMsg = err;
});
})
}
lee1
December 7, 2019, 7:58pm
4
@doughammack
Remove the brackets around needsToBeInserted. That makes your existing array the only element in a new array.
@lee1 Thanks for the response. When I take away the brackets I get no entries inserted, when I leave the brackets I get 1 entry and its blank
lee1
December 7, 2019, 8:28pm
6
I think needsToBeInserted should be an array of objects, not an array of arrays. So also change
[item.title, item.youthHms, item.youthEq, item.youthSms]
to
({item.title, item.youthHms, item.youthEq, item.youthSms})
You need the parenthesis else it would be interpreted as a code block.
Thanks Lee. When I tried that I get an array of “undefined” but I get an array has the correct number of objects
lee1
December 7, 2019, 9:03pm
8
Haha we’ll get there eventually.
let needsToBeInserted = items2.map(item => ({
title: item.title,
youthHms: item.youthHms,
youthEq: item.youthEq,
youthSms: item.youthSms
}));
@lee1 You sir are the man! That got it, it is know working correctly!!!