Reputation: 462
I Stored the data in object form and I want to add or update one filed like "Status" into each object like invitee1 and invitee2 using cloud functions.I tried but it is updated at the end of all the objects. How to add the field at the end of each object using cloud functions or Firestore triggers. I am getting this type of error when I use update statement
var dbref = db1.collection('deyaPayUsers').doc(sendauthid).collection('Split').doc(sendauthid).collection('SentInvitations').doc(senderautoid);
var msg1 = receiverph +"" + status +" to pay $"+document.Amount;
var fulldoc = dbref.get()
.then(doc => {
if(!doc.exists){
console.log('No such document');
}else{
console.log('Document data :',doc.data());
d1 = doc.data();
console.log("d1 is"+d1);
for(var k in d1){
var p = d1[k].PhoneNumber;
console.log("ivitees phone"+p);
if(receiverph == p)
{
console.log("p"+PhoneNumber);
console.log("the phonenumber matches");
var updated = dbref.p.update({"Status":status});// **i got error here like "update is not define"**
i tried another way to update
var updated = dbref.d1[k].PhoneNumber.update({"Status":status});// here i got error like "Can not read property of invitee1 of undefined"
How to solve that error.
Upvotes: 1
Views: 616
Reputation: 1723
You can't update the field directly. Do like this:
With the document reference,
for(var k in d1) {
if (receiverph === d1[k].PhoneNumber) {
doc.ref.update({
[`${k}.Status`]: status
})
}
}
Upvotes: 1