1

Have a strange problem with react-native-firebase library:

Steps:

Try to fetch data with the firestore:

await firestore().collection(collectionName)
                .where(ConversationModel.refs.employees, 'array-contains', '646').get();

where 646 - element in array

When I use an array of strings, this code works as expected

But when I set the number value (646) and try to fetch the array of numbers - this code returns empty result.

Correct sample:

await firestore().collection(collectionName) .where(ConversationModel.refs.employees, 'array-contains', '646').get();

enter image description here

Wrong sample:

await firestore().collection(collectionName) .where(ConversationModel.refs.employees, 'array-contains', 646).get();

enter image description here

UPDATE: Fixed in 6.1.0 https://invertase.io/oss/react-native-firebase/releases/v6.1.0

2 Answers 2

0

The official documentation found here https://firebase.google.com/docs/firestore/query-data/queries says "You can use the array-contains operator to filter based on array values", I believe the key take away here is "values".

In the correct one you are using a string and in the wrong one you are using a Integer. It might then be that you have stored the values as Text string and not as Integers. Supported data types listed here https://firebase.google.com/docs/firestore/manage-data/data-types

Sign up to request clarification or add additional context in comments.

Comments

0

Firestore queries are type-sensitive. If you want to get documents where the employees array contains the number 646, you need to build a query that checks for that number. So something like:

await firestore().collection(collectionName)
            .where(ConversationModel.refs.employees, 'array-contains', 646).get();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.