Home > Software design >  How can read data of other users (not user.uid) from firestore
How can read data of other users (not user.uid) from firestore

Time:12-09

I want to read the data of not authenticated users from firestore collection location is users->swipes->id enter image description here

my attemp not success


const querySnapshot = await getDocs(collection(db, "users",id,"swipes"));
querySnapshot.forEach((doc) => {
  // doc.data() is never undefined for query doc snapshots
  console.log(doc.id, " => ", doc.data());
});

I want to read id in swipes , not from user.uid here 3 users in users if want to read from user.uid , it is easy

collection(db, "users",user.id,"swipes")

if want to read from others users I confuse plz help

CodePudding user response:

If you want to read the swiped subcollection from all users, you'll want to use a collection group query. This type of operation reads all collections with a specific name.

In your case that'd be:

const querySnapshot = await getDocs(collectionGroup(db, "swipes"));
querySnapshot.forEach((doc) => {
  console.log(doc.id, " => ", doc.data());
});
  • Related