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!