0

I am trying to write a basic node.js script that does simple queries to my Firestore db. This below script works when I run node src/index.js. The problem is that is never finishes. This is the code.
"src/index.js"

import { initializeApp } from 'firebase/app'
import {
  getFirestore, collection,
  query, where, getDocs,
  orderBy
} from 'firebase/firestore'
import * as dotenv from 'dotenv'
dotenv.config()

const firebaseConfig = {
  apiKey: process.env.APP_ID_KEY,
  authDomain: process.env.PROJECT_ID + ".firebaseapp.com",
  projectId: process.env.PROJECT_ID,
  //storageBucket: process.env.PROJECT_ID + ".appspot.com",
  messagingSenderId: process.env.MESSENGING_SENDER_ID,
  appId: "1:" + process.env.MESSENGING_SENDER_ID + ":ios:" + process.env.APP_ID_ENDPART
}

// init firebase
initializeApp(firebaseConfig)

// init services
const db = getFirestore()

// collection ref
const colRef = collection(db, '<MY DB COLLECTION>')

// queries
const q = query(colRef, where("email", "==", "<EMAIL THAT I KNOW IS IN THE DB>"))

const querySnapshot = await getDocs(q);
querySnapshot.forEach((doc) => {
  // doc.data() is never undefined for query doc snapshots
  console.log(doc.id);
});

Again, it actually does work. In my terminal, the uid of the entry appears in the console but the command never finishes and the console just hangs.

Why is the command not finishing? Is there any reason to believe that there is Firebase code still running on the backend using up money? I killed the terminal command on my end but is it possible that Firebase is still querying for infinity spending my money?

ChristianOConnor
  • 820
  • 7
  • 29
  • 1
    Firebase actively listens for changes to the database by default – Konrad Oct 22 '22 at 21:49
  • @KonradLinkowski yeah but this example doesn't show how to execute a query with a "where" in it. Also, are there several listener processes opened now that I need to close? How do I do that? – ChristianOConnor Oct 22 '22 at 22:20
  • 1
    When you close the process it won't query anymore. I'm also pretty sure that background checking like that is not billable – Konrad Oct 22 '22 at 22:25

0 Answers0