[Bug]: Firestore - Where condition does not work in certain scenarios.
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.
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:
For all the other cases, such as passing text strings or a combination of text, numbers, or special characters… it works correctly:
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.
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
-
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.
-
Connect to the database by creating a Datasource on you Appsmith application.
-
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.
-
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
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
},
};