Reputation: 299
I am using datastore from google-cloud-cpp. I have a Firestore emulator running on the same project as my data store. My datastore API is datastore in native mode, which is Firestore.
// namespace FIRESTORE = google::cloud::FIRESTORE;
template <typename ModelType>
class Firestore
{
public:
// Constructor
Firestore()
{
auto &app = drogon::app();
auto customConfig = app.getCustomConfig();
project_id = customConfig.get("gcloud_project_id", "default-project").asString();
// Initialize the Firestore client with the necessary connection
google::cloud::Options options;
// Specify the emulator endpoint. This URL is just an example; adjust the port as needed.
//std::string emulator_endpoint = "http://localhost:9019";
// Create client options with the emulator endpoint
//auto options = google::cloud::datastore_v1::ClientOptions::CreateDefaultClientOptions().value();
//options.set(emulator_endpoint);
// options.set<google::cloud::ProjectIdOption>(project_id);
client_ = std::make_unique<google::cloud::datastore_v1::DatastoreClient>(
google::cloud::datastore_v1::MakeDatastoreConnection());
};.
I wonder if there is a way to set this up to use a local emulator, and if so, can it be connected to the Firebase Firestore emulator?
Upvotes: 0
Views: 117
Reputation: 462
According to the documentation, Firestore Emulator is used to test Firestore in Datastore mode. The emulator can be used in all Datastore mode client libraries. Since you're using native mode, it is backwards compatible with Datastore.
To connect to the emulator, you have to set the DATASTORE_EMULATOR_HOST environment variable. It should automatically connect to the emulator after its been set.
export DATASTORE_EMULATOR_HOST="HOST:PORT"
Firebase Firestore Emulator can only be connected with a Firebase project.
References:
Upvotes: 0