简体   繁体   English

如何检查文档参考的javascript数组中是否存在Firestore文档参考?

[英]How to check if a Firestore Document reference exist in a javascript array of Document references?

I have a document with an array as it's field which basically stores references to other documents. 我有一个带有数组的文档,因为它的字段基本上存储了对其他文档的引用。

When I fetched the document data and checked if a document reference is in the array, I always get a result that it doesn't exist in the array, even if its already in there. 当我获取文档数据并检查文档引用是否在数组中时,我总是得到一个结果,即使它已经在数组中,该引用也不存在于数组中。

//The below codes logs as 'false'

console.log([db.doc('collectionName/docId')].includes(db.doc('collectionName/docId')))

console.log(db.doc('collectionName/docId') === db.doc('collectionName/docId'))

I think there is something unique with each document reference. 我认为每个文档参考都有一些独特之处。 If this is the case then how can I check if a document reference exists in an array of document references? 如果是这种情况,那么如何检查文档参考数组中是否存在文档参考?

Since the document reference objects are not equal, the only way I could do it was to compare the id of the document objects, to see if they match. 由于文档引用对象不相等,所以我唯一的方法是比较文档对象的ID,以查看它们是否匹配。

This returns true : 返回true

console.log([db.doc('/collectionName/docId')]
.some(doc => doc.id === db.doc('/collectionName/docId').id));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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