0 votes

As save the same ID that is generated when you push on a property of the object in firebase?

Currently I have a node called 'releases', which contains the following object:

introducir la descripción de la imagen aquí

As I do so that the same key that is generated by push of the firebase in that object is "L_E401l0yZ...." save it in a property of that object, so that it is like this:

   fecha_creacion: "2019-3-5"
   mensaje: "mensaje del primer comunicado"
   titulo: "primer comunicado"
   id: "L_E401I0yZmGMn12L07"

What I have done in the following way, but I have not had results:

        let vm = this;
        let fecha_actual = new Date()
        let anio = fecha_actual.getFullYear();
        let mes  = fecha_actual.getMonth()+ 1;
        let dia  = fecha_actual.getDate();
        let hoy = anio + "-"+mes+"-"+dia;

        var myRef = firebase.database().ref().push();
        var key = myRef.key();

            titulo: comunicado.titulo,
            mensaje: comunicado.mensaje,
            fecha_creacion: hoy,
            id: key
            console.log("Comunicado creado exitosamente");
            vm.dialogCrear = false;


Gastón Saillén Points 1822

Where returns a promise you can send the object with the value of your key

                myRef.child(snapshot.key).update({"id": snapshot.key})
                console.log("Comunicado creado exitosamente.");
                vm.dialogCrear = false;


HolaDevs is an online community of programmers and software lovers.
You can check other people responses or create a new question if you don't find a solution

Powered by: