firebase / firebase/firebase-js-sdk

Issue with documentId() in conjunction with an or filter

Open
#8,049 4 comments 0 reactions 1 assignee Claimed by @cherylEnkidu View on GitHub
api: firestore bug internal-bug-filed stack:ReactNative
Dominant language
TypeScript
Stars
5.1k
Forks
1k
Avg merge
2d 21h
Merged PRs (30d)
37

Description

### Operating System

windows 11

### Browser Version

Windows 11 Pro 23H2 22631.3155

### Firebase SDK Version

9.21.0

### Firebase SDK Product:

Firestore

### Describe your project's tooling

We are using firebase alongside expo to create an all platform app.

"@react-native-firebase/analytics": "^18.2.0",
"@react-native-firebase/app": "^18.2.0",
"@react-native-firebase/app-check": "^18.2.0",
"@react-native-firebase/auth": "^18.2.0",
"firebase": "^9.21.0",

### Describe the problem

We were tring to accomplish a composite query that would fetch documents by Id or other property. The problem is whenever we try to use the documentId() method, the app throws an error saying we can't use that query because we need to create an index.

![image](https://github.com/firebase/firebase-js-sdk/assets/83284629/2705f593-0d57-4547-bee3-47e89325298e)

then when we follow the link to create the query we face a firebase error:

![image](https://github.com/firebase/firebase-js-sdk/assets/83284629/19f11afc-2ab2-4d48-8af3-7aa4de9e32ae)

so we can't really query by id or another document field.

Because changing it to this works no problem and doesn't request you to create an index
```ts
.where(Filter.or(Filter.where('field1', '==', 'value'), Filter.where('field2', '==', 'value')))
```

### Steps and code to reproduce issue

minimal reproducible code:

```ts
import { firestore } from 'firebase-admin'
import FieldPath = firestore.FieldPath
import Filter = firestore.Filter

const db = firestore()

export async function run(db: FirebaseFirestore.Firestore) {

db.collection('farms')
.where(Filter.or(Filter.where(FieldPath.documentId(), '==', 'value'), Filter.where('field2', '==', 'value')))
.get()
.then((snapshot) => {
console.log(snapshot)
})
}

```

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.