Trying to get query results based on current user id. Which is stored in the documents collection under field "uid".
This is my code:
function Channels() {
const currentUid = auth.currentUser.uid;
const query = firestore
.collection("multitwitch")
.where("uid", "==", currentUid)
.orderBy("createdAt");
const [channels] = useCollectionData(query);
return (
<>
<main>
<div>
{channels &&
channels.map((chan) => (
<ChannelStrip key={chan.id} channel={chan} />
))}
</div>
</main>
</>
);
}
function ChannelStrip(props) {
const { twitchchannel } = props.channel;
return (
<>
<iframe
src={`https://player.twitch.tv/?channel=${twitchchannel}&parent=localhost&muted=true`}
height="300"
width="500"
allowfullscreen
></iframe>
</>
);
}
When I add .where
in the query this show no results.
But when I remove .orderBy
it gives results.
Why is this?
Also tried to add indexing in firestore:
No Luck
Firestore queries work based on the existence of indexes that match exactly with the conditions and ordering of each query. By default Firestore automatically indexes all individual fields of your documents, which works for most simple queries.
If you have both a where clause and an order by on different fields, you will need a composite index on those two fields and such indexes are not automatically created. You will instead have to create the index manually, which is likely what you forgot to do.
There are two ways to do create the missing index: