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

432
Visualizações
access firestore from firebase-functions using web version 9 interface (modular)

I have to access a firestore database within firebase functions. I use the following code to get a firestore instance:

import { initializeApp } from "firebase-admin/app"
initializeApp();

import { getFirestore } from 'firebase-admin/firestore'
const db = getFirestore();

This instance can be used to access the database

db.collection('test').add( { anything: 123 } )
db.collection('test').doc('test123').set( { afield: 1234 } )
db.collection('test').doc('test123').get()

According to https://firebase.google.com/docs/firestore/query-data/queries#web-version-8 this is "Web version 8 (namespaced)" interface for accessing firestore databases.

How can I use the "Web version 9 (modular)" interface? The version 9 example from the same page:

import { collection, doc, setDoc } from "firebase/firestore"; 
const citiesRef = collection(db, "cities");

results in the following error:

FirebaseError: Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore

Is there a way to query firestore with admin privileges using modular interface?

Thank You!

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

The Admin SDK does not use functional syntax totally yet. The Web version 8/9 are client SDK. Refer to NodeJS tab of the documentation when using Firebase Admin SDK.

Also you are importing collection() from Firebase client SDK but it seems the db is initialized using getFirestore() from Firebase SDK that might not work properly.

over 4 years ago · Santiago Trujillo 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