简体   繁体   中英

Firestore React get document by URL

I have a question about the operation that can be used with firestore

( url<\/strong> : localhost\/dashboard\/users<\/em> )

( url<\/strong> : localhost\/dashboard\/user\/1<\/em> )

If by "clean" you mean integers or shorter UIDs then you'll can store a field in user's Firestore document eg {shortUid: 1}<\/code> (or set that short UID as document ID at first place) and then query based on the ID:

const userId = getIdFromURL();

const user = await getDocs(collection(db, "users"), where("shortUid", "==", userId))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM