'Lack of null inequality support in Firestore's PHP SDK
We are able to run null inequality just fine on the JavaScript SDK (client or admin), but we are unable to in PHP? To me it seems this is a backend feature which is already supported by Firestore, but throws an error in PHP.
->where('preorders', '!=', null)
Uncaught InvalidArgumentException: Null and NaN are allowed only with operator EQUALS.
Whereas the equivalent in JS SDK works just fine.
query(q, where('preorders', '!=', null))
Since I cannot open an issue in google's PHP SDK repo here, is there any way we can find a reason as to why this is not possible?
Solution 1:[1]
The documentation says, :
“A field exists when it's set to any value, including an empty string (" "), null, and NaN (not a number). Note that null field values do not match != clauses, because x != null evaluates to undefined.”
Explanation : Yes, even if we add an empty string, null,( supported data type in Firestore) or NaN, it doesn't mean that the field doesn't exist. It definitely exists and holds one of those values. And coming to when we compare x != null in where clauses, x != null evaluates undefined, but for non-exist fields. And undefined is not a supported data type in Firestore, according to this Firestore supported data type.
So we can compare .where(x!=null) and it is supported, but it evaluates to undefined for non-existent fields.
As mentioned in similar thread, the version release of v7.21.0 in Firestore JS SDK supports the != operator with where clause from version 7.21.0
But while digging deeper in the documentation, I found that php5 supports != operator as you can see in the code snippet, but the php8 does not support != operator yet and the workaround is using not-in instead of it as shown in this code snippet.
Maybe you are trying to use php version >5 and hence the error.
There is already an open issue on this, in GitHub. You may follow the link for updates and changes or you can create a new request here.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
