My database looks like:
db-dev
user-metadata
portfolios
meta
pending
userId
events-collection
doc1
doc2
...
userId2
events-collection
doc1
doc2
...
verified
userId
events-collection
doc1
doc2
...
userId2
events-collection
doc1
doc2
...
I want to fetch all docs that belong to verified events-collection. Following this answer and this Blog Post I tried to do the following:
export const getVerifiedEvents = async (eventType: DocumentType) => {
//eventType is either pending or verified
const rootRef = Server.db.collection(
`${constDocumentRefs.merchants_meta_loc}/${eventType}`
);
const documents = await const documents = await Server.db
.collectionGroup('events-collection')
.orderBy(documentId())
.startAt(rootRef.path)
.endAt(rootRef.path + '\uf8ff')
.get();
return documents.docs.map((doc) => doc.data());
};
But the above code throws me the following error:
TypeError: Cannot read properties of undefined (reading 'documentId')
13 | const documents = await Server.db
14 | .collectionGroup('events-collection')
> 15 | .orderBy(firestore.documentId())
| ^
16 | .startAt(rootRef.path)
17 | .endAt(rootRef.path + '\uf8ff')
18 | .get();
Here's how my Server instance looks like:
import { auth, db, storage } from './firebase_server';
const firebaseServer = {
auth,
db,
storage,
};
export default firebaseServer;
Where auth,db and storage are imported from following files:
import admin from 'firebase-admin';
const keyString = process.env.FB_ADMIN_PRIVATE_KEY ?? '{"privateKey": ""}';
const { privateKey } = JSON.parse(keyString);
if (privateKey === '') {
console.log('FIREBASE_PRIVATE_KEY is not set');
}
if (admin.apps.length === 0)
admin.initializeApp({
credential: admin.credential.cert({
clientEmail: process.env.FB_ADMIN_CLIENT_EMAIL,
privateKey: privateKey,
projectId: process.env.FB_ADMIN_PROJECT_ID,
}),
});
const db = admin.firestore();
const auth = admin.auth();
const storage = admin.storage();
export { auth, db, storage };
To be precise, I am using firebase-admin
["firebase-admin": "^10.0.1"] npm package and this is just not working whereas in lots of places they have been directly using documentId() with ease. What's the correct grammar for the same?