Cloud Firestore now supports not equal queries

Hi, Firebase developers!

In what might be my shortest (but most exciting) blog post this year, we wanted to let you know that Cloud Firestore now has support for not-equal queries. This means you can now query, for example, all documents in a “Projects” collection where the project’s status field is not equal to the value "completed"

On a similar note, Cloud Firestore also supports not-in queries, where you can query for documents where fields are not in a list of values. So you can, for example, find all documents in a “Projects” collection where the status isn’t equal to "completed" or "dropped" with a single query.

Note that neither of these calls will allow you to fetch documents where this field doesn’t exist. If a field is completely missing from a document, it will not be returned in your query results.

Notice that project 4593 does not get included in the results, because it has no owner field

When it comes to combining these not-equal operators with others in the same query, they have many of the same restrictions as other inequality operators (<, >=, etc.). You can’t use a != operator against two different fields, for instance. Similarly, you can’t use a != query on one field and then sort by a second field. And combining a != query in one field with a == query in another field requires your creating a composite index. Make sure to check out the official documentation for all the details.

This functionality is currently supported by the iOS, Android and Web client libraries, as well as the Node.js and Java server-side SDKs. Support for C++ and other server libraries is coming soon.

We hope this new addition makes it a little easier to develop Cloud Firestore-powered applications, and as always, if you have questions, please feel free to reach out on StackOverflow.

Happy coding!