Fİrebase document ref path does not getting datas

I have a basic firebase question could you help me please?

My firebase like this: User > doc(userid) > user informations and the other collection posts > doc (doc of posts) > post content etc.

Now I have a collectionGroup:

  const postRef = useFirestore().collectionGroup("posts");

  const { status, data } = useFirestoreCollection(postRef);

enter image description here

I want to go back using this collection group. I mean now we are in posts collection, but i want to go back, so i want to go users section. How can i do this? Usign reference.path maybe?

my code:

{data?.docs?.reverse().map((d, index) => {
                return (
                  <>
                    <div className="d-flex justify-content-center">
                      <div className="post__body align-items-center">
                        <div className="post__header">
                          <div
                            className="post__avatar d-flex"
                            style={{
                              padding: "10px",
                              marginLeft: "-10px",
                            }}
                          >
                            <Avatar src={img1} />
                            <h3 className="profile-post-username">
                             {console.log(d.ref.path)}{" "}
                            </h3>
                          </div>
                          <div className="post__headerDescription asd">
                            <div className="">{d.data().content}</div>
                          </div>
                        </div>
                        <img src={d.data().imageURL} alt="" />
                        <div className="post__footer">
                          <FavoriteBorder fontSize="medium" />
                          <Publish fontSize="medium" />
                        </div>
                      </div>
                    </div>

                    <hr></hr>
                  </>
                );
              })}

If we look console, it gives this:

users/NXh8KBd3OUQA4s8048ADy1KqKn33/posts/riruD1DedJzSmoM
users/AhFDgUrP0oWRNgexbvM6sOuNMAu2/posts/stsMitLGk8VKwHC

Now, using these informations, i want to get users email or users names etc.

here homepage: [![enter image description here][2]][2]

if i do like this it gives users doc id: [![enter image description here][3]][3]

updated codes v2: Now i create new jsx document. Its names User Infos. here:

const UserInfos = () => {
  const userRef = useFirestore().collection("users");

  const { status, data } = useFirestoreCollection(userRef);

  return (
    <div
      className="post__avatar d-flex"
      style={{
        padding: "10px",
        marginLeft: "-10px",
      }}
    >
      <Avatar src={img1} />
      <h3 className="profile-post-username">
        {data?.docs?.map((index) => index.data().email)}{" "}
      </h3>
    </div>
  );
};

now, the homepage codes like this:

 {data?.docs?.reverse().map((d, index) => {
                return (
                  <>
                    <div className="d-flex justify-content-center">
                      <div className="post__body align-items-center">
                        <div className="post__header">
                          <UserInfos/>
                          <div className="post__headerDescription asd">
                            <div className="">{d.data().content}</div>
                          </div>
                        </div>
                        <img src={d.data().imageURL} alt="" />
                        <div className="post__footer">
                          <FavoriteBorder fontSize="medium" />
                          <Publish fontSize="medium" />
                        </div>
                      </div>
                    </div>

                    <hr></hr>
                  </>
                );
              })}

and it's screenshot here: enter image description here



Read more here: https://stackoverflow.com/questions/68489371/f%C4%B0rebase-document-ref-path-does-not-getting-datas

Content Attribution

This content was originally published by efesahin at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: