FireStore now supports IN Queries & array-contains!!
Firestore with new in and array-contains-any queries.
This is the good news for cloud firestore developers, the pain point they are facing unable to use of ‘in’ operator.
Cloud Firestore is a NoSQL document database that lets you easily store, sync, and query data for your mobile and web apps — at a global scale. Cloud Firestore is a flexible, scalable database for mobile, web, and server development from Firebase and Google Cloud Platform.
in query, you can query a specific field for multiple values (up to 10) in a single query. You do this by passing a list containing all the values you want to search in, and Cloud Firestore will match any document whose field equals one of those values.
in queries are the best way to run simple OR queries in Cloud Firestore. For instance, if the database for your E-commerce app had a
customer_orders collection and you wanted to find which orders had a “Ready to ship”, “Out for delivery” or “Completed” status, this is now something you can do with a single query, like so:
[“Ready to ship”, “Out For Delivery”, “Completed”]
one more example:-
citiesRef.where('country', 'in', ['India', 'Japan','CostaRica']);
Firestore launched another feature similar to the
in query, the
array-contains-any query. This feature allows you to perform
array-contains queries against multiple values at the same time.
In your e-commerce site has plenty of products with an array of categories that every item belongs in, and you want to fire a query to fetch products with a category such as “Appliances” or “Electronics” then.
one more example:
Note:- These queries are also supported in the Firebase console, which gives you the ability to try them out on your dataset before you start modifying your client code.
- As we mentioned earlier, you’re currently limited to a maximum of 10 different values in your queries.
- You can have only one of these types of operations in a single query. You can combine these with most other query operations, however.