是否有设置数据存储以使用firebase firestore模拟器?即本机模式下的数据存储

问题描述 投票:0回答:1

我正在使用 google-cloud-cpp 的数据存储。我有一个 Firestore 模拟器与我的数据存储在同一项目上运行。我的数据存储API是本机模式的数据存储,即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());
    };.

我想知道是否有办法将其设置为使用本地模拟器,如果可以,是否可以连接到 Firebase Firestore 模拟器?

c++ google-cloud-firestore gcloud google-cloud-cpp
1个回答
0
投票

根据文档,Firestore Emulator用于在Datastore模式下测试Firestore。该模拟器可用于所有数据存储模式客户端库。由于您使用的是本机模式,因此它与数据存储向后兼容。

连接到模拟器,您必须设置DATASTORE_EMULATOR_HOST环境变量。设置后应该会自动连接到模拟器。

export DATASTORE_EMULATOR_HOST="HOST:PORT"

Firebase Firestore Emulator 只能与 Firebase 项目连接。

参考资料:

  • 连接您的应用程序并开始原型设计

  • 将您的应用连接到 Cloud Firestore 模拟器

© www.soinside.com 2019 - 2024. All rights reserved.