My current task involves setting up a Firebase Firestore Database in order to filter it based on a specific field value within a document. The collection I am working with is named "PRD" and consists of thousands of documents, each sharing the same set of fields. Among these fields is a GTIN Number (String) which uniquely identifies each item. When receiving this GTIN Number from a barcode scan (referred to as data), my goal is to retrieve the Medication Name (known as DSCRD and located in a different field within the documents) associated with that particular GTIN Number.
Despite my efforts, I have encountered challenges when attempting to fetch the required data from Firebase. So far, various retrieval methods have been tested without success. Currently, the code for data retrieval appears as follows:
import { dbh } from "../firebase/config"
import firestore from '@react-native-firebase/firestore'
dbh.collection('PRD')
.where('GTIN', '==', data)
.get()
.then(documentSnapshot => {
console.log('MedData',documentSnapshot.data())
});
The main issue lies in filtering the correct medication using the provided GTIN from the barcode scanner, and then storing the corresponding description field value into a variable.
It's worth noting that Firebase has been correctly set up, as evidenced by successful write operations to collections and documents within the database.
Below is the database structure, showcasing the PRD Collection housing all the medications, each containing GTIN and DSCRD Fields: