Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

591
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda