MichaelSolati / geofirestore-js

Location-based querying and filtering using Firebase Firestore.
https://geofirestore.com
MIT License
505 stars 58 forks source link

Multiple documents by id #180

Closed molimauro closed 4 years ago

molimauro commented 4 years ago

Hello, thanks for the amazing library.

I was wondering if I can query multiple documents by id using something similar to firebase.firestore.FieldPath.documentId(). I tried also with geofirestore.FieldPath.documentId() without success. Can someone point me in the right direction?

Thanks in advance.

MichaelSolati commented 4 years ago

So geofirestore only replicates the functionality of a firestore instance (firebase.firestore()) not the firestore namespace (firebase.firestore). So If you want to create FieldPath objects you'll need to use the namespace (firebase.firestore). However you can use a FieldPath object in geofirestore to make a query.

I think that helps, let me know!

molimauro commented 4 years ago

Thanks for the quick reply. I tried with:

const query = geocollection
    .where(firebase.firestore.FieldPath.documentId(), "in", [
        "2EELdMWlmpBYpw4l8Jxr",
        "2mvgJlCEXhTcNfeyfm6f",
    ])
    .get()

but I got this error:

index.cjs.js:160 Uncaught FirebaseError: Function Query.where() called with invalid data. Invalid field path (d.[object Object]). Paths must not contain '~', '*', '/', '[', or ']'

If I try this:

const query = firestore
    .collection("collection")
    .where(firebase.firestore.FieldPath.documentId(), "in", [
        "2EELdMWlmpBYpw4l8Jxr",
        "2mvgJlCEXhTcNfeyfm6f",
    ])
    .get()

This obviously works but I get the documents with the default firestore data structure instead of the geofirestore structure.

Am I missing something? Or there is another way to retrieve multiple documents by id? Thanks.

MichaelSolati commented 4 years ago

Can you please create a stackblitz example? Use this as a template if you'd like https://stackblitz.com/fork/geofirestore-issue-sandbox

molimauro commented 4 years ago

Hi, I found out that I was stuck at version 3.4.3. With the latest version the problem seems gone. Thanks for your help!