Error getting firebase documents

0

I have a collection in firebase which has a few documents. I have a javascript code which connects to this database.

window.onload = inicializar();
var dbRef;
function inicializar() {
    dbRef = firebase.firestore().collection(PRODUCTOS); //dbRef contiene la referencia a mi coleccion de documentos en Firestore
    firebase.auth().signInAnonymously().catch(function(error) {
        console.log("Codigo de Error: " + error.code);
        console.log("Mensaje de Error: " + error.message);
    });
    getAll();
}

function getAll() {
    dbRef.get().then((snapshot) => {
        snapshot.docs.forEach(doc => {
            console.log(doc.data());
        })
    });
}

The problem is that executing this code gives me the following error: Uncaught TypeError: Can not read property 'get' of undefined Mark this error on line 13 when inspecting the code in the browser.

I hope you can help me. From already thank you very much. :)

    
asked by Joaquin Gonzalez 12.12.2018 в 00:55
source

0 answers