prescottprue / react-redux-firebase

Redux bindings for Firebase. Includes React Hooks and Higher Order Components.
https://react-redux-firebase.com
MIT License
2.55k stars 559 forks source link

FieldPath.documentId doesn't exist #1117

Open dsgriffin opened 3 years ago

dsgriffin commented 3 years ago

Do you want to request a feature or report a bug?

Bug

(If this is a usage question, please do not post it here—post it on gitter. If this is not a “feature” or a “bug”, or the phrase “How do I...?” applies, then it's probably a usage question.)

What is the current behavior?

FieldPath does not exist on FieldPath when retrieving via the useFirestore hook.

What is the expected behavior?

Trying to retrieve multiple documents in one go via in inside useFirestoreConnect e.g. this should work:

const firestore = useFirestore();

useFirestoreConnect(() => [{
    collection: 'examples',
    where: [firestore.FieldPath.documentId(), 'in', ['a', 'b']],
    storeAs: 'examples'
}]);

But the only property that exists on FieldPath currently is isEqualTo.

If I try to use firebase directly e.g.

import firebase from '../settings';

useFirestoreConnect(() => [{
    collection: 'examples',
    where: [firebase.firestore.FieldPath.documentId(), 'in', ['a', 'b']],
    storeAs: 'examples'
}]);

I get a ton of type issues and cannot proceed.

Which versions of dependencies, and which browser and OS are affected by this issue? Did this work in previous versions or setups?

Latest Stable (3.10.0)

Gsiete commented 2 years ago

Did you see this? https://github.com/prescottprue/redux-firestore/issues/176

dsgriffin commented 2 years ago

Did you see this? prescottprue/redux-firestore#176

yep, I've been using where: ['__name__', '==', ...] as it's the only working solution currently, but a bit of a hack.

prescottprue commented 2 years ago

Not sure why the statics wouldn't be available on the instance returned from useFirestore, but you should be able to be pull straight from the firebase SDK (since it is just a static):

import firebase from 'firebase/app'
import 'firebase/firestore'

// Then later
firebase.firestore.FieldPath.documentId()

@dsgriffin Thanks for sharing the workaround, that is also valid!

dsgriffin commented 2 years ago

@prescottprue no worries!

just tried using firebase.firestore.FieldPath.documentId() inside useFirestoreConnect's where clause.

discovered that type WhereOptions expects a string as the first argument, while documentId() returns a FieldPath. using a toString() on it might be a solution

fseha-hagos commented 2 weeks ago

it works for me....

import firebase from firebase/firestore

const collectionRef = collection(db, 'myData'); const q = query(collectionRef, where(firebase.documentId(), 'in', ['a', 'b']));