Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide Document id when fetching a firestore collection #12

Open
m4rrc0 opened this issue Dec 28, 2018 · 6 comments
Open

Provide Document id when fetching a firestore collection #12

m4rrc0 opened this issue Dec 28, 2018 · 6 comments

Comments

@m4rrc0
Copy link

m4rrc0 commented Dec 28, 2018

Hey @rakannimer , I was trying out your lib to quickly build a Firebase project because I probably won't need any fancy feature for quite a while but got 'stuck' on what I see as a pretty basic use case.
I am querying a firestore collection and I want to update a document in that collection but I don't have the id...
It should be pretty easy to set a key for the metadata in each document of the array returned, something like _metadata or _documentMetadata or whatever.
I tried to make sense of the code but I have never used typescript and I am missing a few pointers to figure this out quickly enough.
Happy holidays :)

@m4rrc0
Copy link
Author

m4rrc0 commented Dec 28, 2018

I see there is an __id key on the collection itself but it is null obviously. Maybe you intended to set ids on docs and it is a bug then ?

@rakannimer
Copy link
Owner

Hey @MarcCoet

Thanks for raising the issue, I added an ids field to the render props args of the collection and an id field to the render props args of the document.

Can you give it a try now ?

I simplified a lot of the code that was a bit contrived. So please feel free to raise any more issues you face 👍

Cheers !

@m4rrc0
Copy link
Author

m4rrc0 commented Jan 2, 2019

Hey @rakannimer . Thanks for your reactivity.
I've just given it a try and somehow the same FirestoreCollection does not work anymore. It seems like it is not taking the path prop properly anymore.

Appart of that I will raise another issue for another part of the code but I will need to go back to my own implementation probably because I have a deadline in 2 days. ;)

@mhelvens
Copy link

I'm running into the same issue. There seems to be no way to simply get all document keys for a given collection.

@RobertSasak
Copy link

For those like me who prefer to have it merged into one object

({ isLoading, value, error, ids }) => 
  value
    .map((v, i) => ({ v, id: ids[i] }))
    .map(({id, name})=> (
      <div key={id}>{name}</div>
    ))

@nicokant
Copy link

Hi, having ids inside the same object would be wonderful!

Currently I'm using a HOC to collect and merge the props before feeding into the dumb component.

import { compose, withProps } from 'recompose';

const enhance = compose(
  withProps(({ value, ids }) => {
    if (value === null || typeof value === 'undefined') return null;
    return {
      value: value.map((val, i) => ({
        ...val,
        id: ids[i],
      })),
    };
  }),
);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants