Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

430
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!