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
  • 565,676
  • 79
  • 828
  • 807
Aravin
  • 6,605
  • 5
  • 42
  • 58

0 Answers0