So I have looked everywhere online and I just can't seem to figure out how to get this to work.
What I am trying to achieve is to find all users that have the same device under their devices. Here is the structure of the Firestore database: Database Image
So recently Firebase released version 5.3.0 of their Javascript library which in their release notes states:
Added 'array-contains' query operator for use with .where() to find documents where an array field contains a specific element.
Firebase Javascript Release Notes
I am trying to use this 'array-contains' in the .where() but i am getting no success. Here is my code:
admin.firestore().collection("users").where("devices",'array-contains', id)
//I get id from another place, i know that id is valid
This is the error i get back from the firebase functions log:
Unhandled error Error: Argument "opStr" is not a valid FieldComparison. Operator must be one of "<", "<=", "==", ">", or ">=". at Object.exports.(anonymous function) [as isFieldComparison] (/user_code/node_modules/firebase-admin/node_modules/@google-cloud/firestore/build/src/validate.js:89:23) at CollectionReference.where (/user_code/node_modules/firebase-admin/node_modules/@google-cloud/firestore/build/src/reference.js:1095:18) at exports.checkIfDeviceIdValid.functions.https.onCall (/user_code/index.js:23:50) at /user_code/node_modules/firebase-functions/lib/providers/https.js:330:32 at next (native) at fulfilled (/user_code/node_modules/firebase-functions/lib/providers/https.js:25:58) at process._tickDomainCallback (internal/process/next_tick.js:135:7)
Here are my dependencies from my package.json:
"dependencies": {
"@google-cloud/firestore": "^0.15.4",
"firebase-admin": "~5.13.0",
"firebase-functions": "^2.0.2"
}
If someone could help me with this and show me an example of how to do this I would greatly appreciate it. Thank you.