appsmith icon indicating copy to clipboard operation
appsmith copied to clipboard

[Bug]: Firestore - Where condition does not work in certain scenarios.

Open felix-appsmith opened this issue 2 years ago • 1 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Description

I have a Firestore Database that stores documents with “name” and “phoneNumber” fields.

image

When I run the “List Documents” query with a “where” condition it doesn’t work if the value I pass to the “phoneNumber” field is a number string, the result is an empty array:

image

For all the other cases, such as passing text strings or a combination of text, numbers, or special characters… it works correctly:

image

image

To verify that this situation only happens in Appsmith, I did some test code with NodeJS and Firestore to execute a where query and it does work. The code connects to a Firestore database and performs the query filtering by the phoneNumber property, which is a string of numbers.

image

var admin = require("firebase-admin");
var serviceAccount = require("./serviceAccountKeys.json");

admin.initializeApp({
  credential: admin.credential.cert(serviceAccount)
});

const db = admin.firestore();
let cafesRef = db.collection("cafes");


db.collection("cafes").where("phoneNumber", "==", "3224563241")
    .get()
    .then((querySnapshot) => {
        querySnapshot.forEach((doc) => {
            console.log(doc.id, " => ", doc.data());
            console.log("\n");
        });
    })
    .catch((error) => {
        console.log("Error getting documents: ", error);
    });
    

Steps To Reproduce

  1. Create a Firestore Database and store some documents. Some of the documents must have some property of type string whose value is a string of numbers, the others can have a value which is a combination of numbers, special characters, or letters, but the property type must be also string.

  2. Connect to the database by creating a Datasource on you Appsmith application.

  3. Run the “List Documents” query with a “where” condition in which the value to be passed is a string of numbers, one of those that you assigned when creating the documents in the database. You will see an empty array as the result of the query.

  4. Run the “List Documents” query with a “where” condition in which the value to be passed is a combination of numbers, special characters, or letters, one of those that you assigned when creating the documents in the database. You will see the document or the documents you were looking for.

Possibly Related Issues

https://github.com/appsmithorg/appsmith/issues/20691 https://github.com/appsmithorg/appsmith/issues/14785

Public Sample App

https://app.appsmith.com/app/firestore-where-problem/page1-645919b51671447b88d3ce2e?embed=true

Environment

Production

Issue video log

No response

Version

Cloud - Appsmith v1.9.18-SNAPSHOT

felix-appsmith avatar May 09 '23 15:05 felix-appsmith

I discovered a new bug with this, so I updated the ticket and added it. The problem is that we cannot filter references with 'where'. I have implemented this workaround:

export default {
  WhereFirestore() {
    const data = GetData.data;
    const where = "tsda12912s";
    const filterdata = data.filter(item => item.number?.id == where)
		return filterdata
  },
};

This can be used for numbers stored as strings.

export default {
  WhereFirestore() {
    const data = GetData.data;
    const where = "1212212";
    const filterdata = data.filter(item => item.phone == where)
		return filterdata
  },
};

felix-appsmith avatar May 10 '23 17:05 felix-appsmith