Search code examples
google-cloud-platformgoogle-cloud-firestoregoogle-cloud-functions

FireStore or FireStoreClient class for Java Firestore client library?


I'm new to using Google Cloud Firestore (without Firebase), just for my Cloud Functions to persist certain state data between executions.

I'm confused what's the difference between FirestoreClient class and FireStore class?

Both documents say they are "firestore client", oh well, one says it's "Firestore server-client", that's the same thing, right? They are all just programmatic interfaces to add, update, retrieve, and delete data in the Firestore database?

The FireStoreClient class seems can directly get, update, and list documents while the FireStore class seems to operate on DocumentReference or QueryDocumentSnapshot? Honestly I'm so confused which means what and not sure which one I should be looking at?

Btw, I really only need a database as a persistence layer between executions of my cloud function and all I'm storing are 3 key-value pair strings, but reliable persistence is important, i.e. using something like MemoryStore, even though much lightweight and easier interface, risks losing data as it's not as durable as something like FireStore. Please let me know in case I'm not making the right call here, thanks!


Solution

  • As you can see there is no inheritance relationship between the FirestoreClient class and the Firestore interface. So a FirestoreClient is not a Firestore. However, both share similar methods that can help you interact with Firestore.

    There are however some differences. The Firestore interface represents a Firestore Database entry point that provides direct access to Firestore Database operations. On the other hand, the FirestoreClient class provides the ability to make remote calls to the backing service. Besides that, please also note the Firestore interface belongs to the com.google.cloud.firestore package, while the FirestoreClient class belongs to com.google.cloud.firestore.v1 (version 1) package.

    Now, according to the use case of your app, you should choose which option fits best for performing Firestore database calls.