You have unlimited access as a PRO member
You are receiving a free preview of 3 lessons
Your free preview as expired - please upgrade to PRO
Contents
Recent Posts
- Object Oriented Programming With TypeScript
- Angular Elements Advanced Techniques
- TypeScript - the Basics
- The Real State of JavaScript 2018
- Cloud Scheduler for Firebase Functions
- Testing Firestore Security Rules With the Emulator
- How to Use Git and Github
- Infinite Virtual Scroll With the Angular CDK
- Build a Group Chat With Firestore
- Async Await Pro Tips
How to Query an Array in Firestore
Episode snippet written by Jeff DelaneyHealth Check: This lesson was last reviewed on and tested with these packages:
- Firebase v5.3
Find an issue? Let's fix it
How you ever wanted to make a query to Firestore for all documents with an array containing a certain value? This is now possible with a new query feature that was released in the JS SDK last week. In addition, the SDK also added support for the atomic addition and removal of elements on an array field on the 5.3.0 release.
This feature was introducted in Firebase SDK v5.3.0, so make sure you have the latest version installed.
Array Contains Query
Firebase introduced an array-contains
operator that can be used with where
to query array fields. It will return all documents that contain a the provided value in the array. Currently, this is only supported with one value, so don’t try chaining more than one of these in a single query.
const col = firestore.collection('carts'); |
Doesn’t get much easier than that.