[英]How to access array in Firestore v9
Articles I've read/tried before:我以前读过/尝试过的文章:
I have a Firestore that looks like this我有一个看起来像这样的 Firestore
Here is the attempted code这是尝试的代码
query(
collection(getFirestore(fireApp), "posts"),
orderBy("uid"),
where(
"uid",
"not-in",
doc(getFirestore(fireApp), "block", "vXLCRjlhOVW6oFOJvtmML6OolKA2")
)
Firestore queries can only filter on values in the document itself, and values you explicitly pass in to the query. Firestore 查询只能过滤文档本身中的值,以及您明确传递给查询的值。 Your doc(getFirestore(fireApp), "block", "vXLCRjlhOVW6oFOJvtmML6OolKA2")
creates a DocumentReference
, so the query returns documents from posts
that don't contain that document reference.您的doc(getFirestore(fireApp), "block", "vXLCRjlhOVW6oFOJvtmML6OolKA2")
创建了一个DocumentReference
,因此查询从不包含该文档引用的posts
中返回文档。
What you want to do instead is:你想要做的是:
So in code:所以在代码中:
const myRef = doc(getFirestore(fireApp), "block", "vXLCRjlhOVW6oFOJvtmML6OolKA2");
const myDoc = await getDoc(myRef);
const blocked = myDoc.data().blockedUserId;
const q = query(
collection(getFirestore(fireApp), "posts"),
orderBy("uid"),
where(
"uid",
"not-in",
blocked
)
)
// TODO: call getDocs or onSnapshot on q
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.