Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

334
Visualizações
Get document data from Firebase Firestore in Node JS

after not finding anything online, I decided to write here. I need to get all the document in the /user/uid collection in Node JS. When I use the Firebase code it replies like this:

Promise {<pending>}

Please help me!

PS: I don't want to use Firebase Admin SDK and await.

"Full" code

var express = require('express');

const { initializeApp } = require("firebase/app");
const { getDatabase, ref, get, child, set, onValue} = require("firebase/database");
const { getFirestore, collection, getDoc, doc} = require("firebase/firestore");

const firebaseApp = initializeApp(firebaseConfig);

// Get a reference to the database service

var app = express();

const PORT = process.env.PORT || 5050

app.get('/', (req, res) => {
    res.send('This is my demo project')
});

const db = getDatabase();
const firestore = getFirestore();


const document = getDoc(doc(collection(firestore, 'users'), "BW5kylV6rtZXtYibpKGc2m1asRm1"));
  
console.log(document);

//Response: "Promise {<pending>}""
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Firebase method calls are asynchronous. So for both the Admin SDK or the JS SDK you have to deal with the asynchronicity, either by using then or by using async/await.

If you receive Promise {<pending>} it is because the asynchronous method getDoc returns a Promise and this promise is not fulfilled, but is still pending.

So you need to dive into the documentation on how to use Promises... or the async/await keywords.

In your case, the following will do the trick:

getDoc(doc(collection(firestore, 'users'), "BW5kylV6rtZXtYibpKGc2m1asRm1"))
.then(snap => {
   console.log(snap.data())
})

However, if you write this code for running on a Node server you own, I would recommend to use the Admin SDK.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda