On Cloud Firestore I have documents with reference to another document this way:
In my example, document Collection A/WJQ9yx67RrqHWQoEp0e2
is referring to document Collection B/rFOEwdw5go4dbitOCXyC
, but there of course, could be infinitely docs referring to one mentioned.
Now I would like to find out all the docs of Collection A
which are referring to this very specific document Collection B/rFOEwdw5go4dbitOCXyC
.
How is this possible? How I can achieve this?
Documentation of Firebase is bit unclear with this.
You're right, there's unfortunately no example of actually making use of a
Reference
data type in the documentation, in fact the only a mention of it is in the Supported Data Types section.Ultimately though, a
Reference
can be used just like any other data type available in Firestore, so can be used to filter & sort data too.To achieve what you're after, you would need to construct a
Reference
that points to the document inCollection B
and then use awhere
clause to filter data on thereference
value ofCollection A
. For example in JavaScript:Looking at the source for
isEqual()
in the Firebase JavaScript SDK, comparing of aReference
(extendsQuery
) is performed by simply checking that the paths match:This would seem to be much like calling
toString()
on both and comparing the string values.I produced a similar example yesterday which lead me to test the possible uses of storing a
Reference
, so that may also apply here.