英文:
How to remove a Document Reference in list with WriteBatch?
问题
我正在使用Firebase Cloud数据库。这个问题与之前的问题类似,但现在我对DocumentReferences
很感兴趣。我查询了一个集合并获得了一系列文档。每个文档都包含一个字段cars
,其中包含DocumentReferences
。每个DocumentReference
引用一个表示汽车的文档。鉴于carsPath
,它是指向汽车文档的路径,我想要从该列表中删除DocumentReferences
。我正在使用WriteBatch
。如果cars
只包含路径,可以通过以下方式轻松实现:
batch.update(snapshot.getReference(), "cars", FieldValue.arrayRemove(carPath));
如果我们有DocumentReferences
而不是Strings
,是否有类似的方法呢?
英文:
I'm using Firebase Cloud database. This question is similar to the previous one but now I'm interested in DocumentReferences
. I queried a collection and got a list of documents. Each document contains a field cars
which contains DocumentReferences
. Each DocumentReference
references a document that represents a car. Given the carsPath
which is a path to the car document, I want to remove the DocumentReferences
in that list. I'm using WriteBatch
. If cars
would contain just the paths, it would be easy by using:
batch.update(snapshot.getReference(), "cars", FieldValue.arrayRemove(carPath));
Is there a way to do something similar if we have DocumentReferences
instead of Strings
?
答案1
得分: 1
只需将 DocumentReference 对象传递给 FieldValue.arrayRemove()
,而不是传递字符串。引用的路径必须与数组中的内容完全匹配。
英文:
Just pass DocumentReference object instead of a string to FieldValue.arrayRemove()
. The path of the reference must match exactly what's in the array.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论