firebase / firebase/firebase-js-sdk

Firebase firestore not accepting multiple array-contains

Open
#5,153 1 comment 3 reactions 0 assignees View on GitHub
api: firestore feature request
Dominant language
TypeScript
Stars
5.1k
Forks
1k
Avg merge
2d 21h
Merged PRs (30d)
37

Description

### [REQUIRED] Describe your environment

* Operating System version: Mac Os Big Sur 11.0.1
* Browser version: Version 91.0.4472.114
* Firebase FireStore version: 8.2.1
* Firebase Product: Firestore

### [REQUIRED] Describe the problem
in the below code, I have 3 keys in my messages list - name, message, participants. Here I want to filter data according to my participants but it's not achievable cause array-contains do not accept multiple values.

I want it to accept keys like array-contains-any but in the array-contains-any result of message work with OR condition but my requirement is AND

Result i want if i query with array-contains(if multiple support is there)
QUERY -
```javascript
db.collection("messages").where("participants", "array-contains", ["33", "127"])
```
RESULT -
```javascript
{
name: "Pawan arora",
message: "test",
participants: ["33", "127"]
},
{
name: "TEST DATA",
message: "new",
participants: ["33", "114", "127"]
}
```

I have also tried it within query it's also not helping me here
```javascript
db.collection("messages").where("participants", "in", ["33", "127"])
db.collection("messages").where("participants", "in", [["33", "127"]])
```

is there any way to achieve the above result with any filter?

#### Relevant Code:

Database data i have -

```javascript
{
name: "Pawan arora",
message: "test",
participants: ["33", "127"]
},
{
name: "TEST NAME",
message: "not working",
participants: ["114", "127"]
}
{
name: "TEST DATA",
message: "new",
participants: ["33", "114", "127"]
},
{
name: "NEW DATA",
message: "new",
participants: ["33", "114"]
}
```
Firebase db image - https://i.stack.imgur.com/D0t94.png

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.