2

How to generate the where in condition as on SQL query

Example:

SELECT * FROM instruments WHERE IN (1, 2, 3, 4)

or

SELECT * FROM instruments WHERE = ANY(1, 2, 3, 5)

Actual Data enter image description here

Actual Code (It fetches 2449 row from DB and filtering required data)

await db.collection('instruments')
        .where('exchange', '==', 'NSE')
        .where('segment', '==', 'NSE')
        .where('instrument_type', '==', 'EQ')
        .get()
        .then((querySnapshot) =>
            {
                querySnapshot.forEach((doc) =>
                {
                    if (NIFTY50.includes(doc.data().tradingsymbol))
                    {
                        instrumentsList.push(doc.data());
                    }
                });
            })
            .catch((error) => {
                console.log("Error getting documents: ", error);
            });

Requirement

Need to fetch only required database from DB where array filter.


Is it possible in firebase?

If not, is there any workaround? I can't fetch all row and filter in code. It has large number of data.

Frank van Puffelen
  • 499,950
  • 69
  • 739
  • 734
Aravin
  • 5,983
  • 3
  • 37
  • 54

0 Answers0