lundi 19 juillet 2021

Firebase 9(modular sdk web ) replacement for fieldPath

I am using the below code with the Firebase SDK 8.

const db = firebase.firestore();
const collectionRef = db.collection(collectionName);

var query = collectionRef.where('isFinal', '==', true);

query = query.where(firebase.firestore.FieldPath.documentId(), 'in', docIds);
return query;

I want to replace it code with the modular SDK. So I have written,

const dbInstance = getFirestore(firebaseApp);
const collectionRef = collection(dbInstance, collectionName);
query(collectionRef, where(???, 'in', docIds));

return query;

But somehow I could not find the syntax to get the FieldPath. From the reference, I can read that,

/**
 * Returns a special sentinel `FieldPath` to refer to the ID of a document.
 * It can be used in queries to sort or filter by the document ID.
 */
export declare function documentId(): FieldPath;

which is imported with

import {documentId} from 'firebase/firestore';

But when I am using it, it results in an error.

Does anyone know what is the correct syntax for this?

Thanks




Aucun commentaire:

Enregistrer un commentaire