I was wondering if there is a way to write a more dynamic subdoc function.
In my case i have a function tat will update a array with a new phone number and an array with a new email. The issue here is that in my data there sometimes is a new phone, a new email or n some cases both. Based on that i will call my function and pass the new object for the email and phone array. To make it more reusable i was hoping to pass an Array of object which i created dynamically to the function. But it complains that (node:868) UnhandledPromiseRejectionWarning: TypeError: bucket.arrayAppend is not a function
Is there another workaround or am i doomed to make individual calls
const upsertPhoneEmailArray = async(bucketName,docID, docArray)=>{
try{
let bucket = bucketWithName(bucketName)
return new Promise((resolve,reject)=>{
bucket.mutateIn(docID)
for( i=0; i < docArray.length; i++)
{
bucket.arrayAppend(docArray[i].path, docArray[i].doc, {createParents: docArray[i].parent})
}
bucket.execute((err, result) => {
if(err) return reject(err);
console.log("Result: " + result)
return resolve(result);
})
})
} catch (error)
{
console.log(error)
}
}