Can I ask why you’re trying to cast a Ref as a string in the first place? More details around the use case might help us come up with a potential solution for you.
I was asking out of curiosity. I thought, from a usability standpoint, it would make sense ToString would return a Ref string representation. Since that is not the case, I was curious as to why it doesn’t. Security reasons or to avoid bad coding practices, maybe?
A Reference is a compound object, containing a reference to a collection, and a document id within that collection. There is no string representation that you can use in a query in place of a reference object.
That said, it is often a requirement to serialize references for use in web-based UIs, so converting a reference to a string could be a useful serialization.
I used Let so that you could see the technique for extracting the elements from the reference.
Once you have that string, to use it in a query you would need to create a valid reference. You would need to split on the space character, and then:
Ref(Collection(collection_name), document_id)
Which assumes that collection_name and document_id are variables in your host language. You didn’t indicate which driver you’re using, so I’m not providing those specific details.