google-cloud-go icon indicating copy to clipboard operation
google-cloud-go copied to clipboard

firestore: Client.Doc() does not take full resource paths

Open wjkoh opened this issue 2 years ago • 2 comments

Client.Doc() does not take a full resource path, such as ""projects/P/databases/D/documents/coll-1/doc-1", while its Python counterpart handles it well. Since DocumentRef has only the Path field exposed, which returns a full resource path, not a short path, it makes sense if Client.Doc() supports it.

wjkoh avatar Jan 24 '23 03:01 wjkoh

Assign me plzz....

lucifer1708 avatar Jan 25 '23 02:01 lucifer1708

Is there any updates on this? There is a common situation. A producer sends out a pub/sub message with a full resource path, and a consumer takes the message and does some firestore operations on that path. It would be great if the consumer could create a DocumentRef from the full path via Client.Doc(fullPath) or get an error if the project ID or database ID do not match. Right now, it's not easy to do on my end since both projectID and databaseID are the private fields of firestore.Client. Check out https://github.com/googleapis/google-cloud-go/blob/0c97c14046893ca5d73d371b3abfe4af297bfd7a/firestore/client.go#L74.

wjkoh avatar Oct 06 '23 07:10 wjkoh

In Python, projectID and databaseID are optional while creating a new client. This is not the case in Go, a client is tied to particular projectID passed in by the user. Taking the full path (a path that contains a different projectID than the one that was used to create the client) in Doc() does not seem wise since any further operations performed on the DocumentRef returned by Doc implicitly use the projectID stored in client wherever required.

Is it possible for you to create a new client from the path and then use it ?

bhshkh avatar Jan 02 '25 20:01 bhshkh

In Python, projectID and databaseID are optional while creating a new client. This is not the case in Go, a client is tied to particular projectID passed in by the user. Taking the full path (a path that contains a different projectID than the one that was used to create the client) in Doc() does not seem wise since any further operations performed on the DocumentRef returned by Doc implicitly use the projectID stored in client wherever required.

Is it possible for you to create a new client from the path and then use it ?

Checked with @daniel-sanche (a maintainer of python-firestore):

  • if the user doesn't pass a project or db when creating a client, it will use defaults. So it still ends up being explicitly tied to a project/database, just like Go
  • Python throws an error when full path not matching the one set in client is used : ValueError: A document must have an even number of path elements

Thus, passing full path, where projectID and databaseID does not match the one in the client, is not supported in other libraries as well.

@wjkoh, I can modify the Go client to take in both short path and full path where projectID and databaseID matches the one in client. Let me know if this is what you are looking for.

bhshkh avatar Jan 03 '25 01:01 bhshkh

@bhshkh Yes, that would be great!

wjkoh avatar Jan 03 '25 01:01 wjkoh