Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

589
Views
Firestore: How to update specific field In payload document?

How do I access and update a specific field in angular firebase but My Data In payload I have put the image link that easy for u:

[Enter This Link and see the Image what I am saying that] 1

 UserVerification(id, _value: number) {


      
     console.log(id,"KKKKK",_value)
    //return this.firestore.collection("DevicesData").doc(id).update({Impact:"100 "}); 
      return this.firestore
     .collection("DevicesData")
     .doc('/' + '00HcetBoNFIOmwEWZ6fo')
    //  .doc(id)
     .update({Impact:"_value"})
     .then(() => {
       console.log('done');
     })
     .catch(function(error) {
      console.error('Error writing document: ', error);
     });
    }

if I use this code then update the data outside the payload but I want to update the data inside the payload ?

Changes

1.Add Document in Collection

Now In this I'll show how can i put the data .first column I write the payload then second column I put string then after last column I put the my data I'll give a data for You soo please put this data in your payload no
{"Topic":"IMPACT","SID":"1","GPSlat":"634312957","GPSlong":"104014716","GPSalt":"49710","GPSspd":"63","GPShead":"29499222","GPSepoch":"1638504105","Impact":"20200"}

2.Second Image you check please

Now In second image I'll show what is the data sequence my data is in one line first and your data is after payload :
Topic:"Impact"
impact:"2000"
etc.
after your sequence of data is in one line (in this second image I clearly what the data sequence soo please check the image clearly) after that you try to put the update query to update the data then I'll show my error in third image 

3.This is my error image

Now you understand what I am saying that ? Or Not
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Your code yes will update the data outside payload, because you didn't specify that. The right way to update a field inside an object in a document (called nested objects):

return this.firestore
           .collection("DevicesData")
           .doc('00HcetBoNFIOmwEWZ6fo')
           .update({'payload.Impact':_value});

You can find the whole documentation here: https://firebase.google.com/docs/firestore/manage-data/add-data#update_fields_in_nested_objects

But this won't work for you, because your payload type is not a map (Object) and that is obvious from the double quote, which mean its a string(make sure when you set it in the right way).
However, if you still want it this way, then you have to update the whole payload string, including other values(also you could do this if the payload is an object, like before):

return this.firestore
           .collection("DevicesData")
           .doc('00HcetBoNFIOmwEWZ6fo')
           .update({payload:{Topic:'IMPACT', MAC:'...', ..., Impact:_value});

UPDATE
I did try the structure and the code as follow, which is the right thing to do:
This is the data before: The data before

Then I run this code:

await firebaseFirestore
        .collection('workflow')
        .doc('jLcWTZBa5Tfjdex5fiYk')
        .update({ 'payload.Impact': 2000 })
        .then(_ => console.info('Success'))
        .catch(error => {
            console.error(error);
        });

I get Success, and the data become like this:
The data after

Other than this I really don't know what is your problem.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!