简体   繁体   English

Google.Cloud.Firestore 未将数据写入 Firestore 模拟器

[英]Google.Cloud.Firestore not writing data to firestore emulator

I'm trying to write data from my local environment (running on iis on my machine) to my Google Firestore emulator.我正在尝试将本地环境中的数据(在我的机器上的 iis 上运行)写入我的 Google Firestore 模拟器。 The code runs, doesn't throw an error BUT the data doesn't seem to be being written to the Firestore emulator.代码运行,不会引发错误,但数据似乎没有被写入 Firestore 模拟器。

Using firebase CLI tools v8.6.0 Google.Cloud.Firestore v2.1.0使用 firebase CLI 工具 v8.6.0 Google.Cloud.Firestore v2.1.0

    string project = ConfigurationManager.AppSettings["firestore_projectid"];
    Environment.SetEnvironmentVariable("FIRESTORE_EMULATOR_HOST", "localhost:8080");
    FirestoreDb db = new FirestoreDbBuilder
        {
            ProjectId = project,
            EmulatorDetection = Google.Api.Gax.EmulatorDetection.EmulatorOnly
              
        }.Build();

    var dto = await GetLiveStreamDto();

    DocumentReference docRef = db
        .Collection("Events")
        .Document("123456789")
         

    await docRef.SetAsync(dto, SetOptions.MergeAll);

For those who are wondering I was able to connect to the emulator via provided code in the question.对于那些想知道我能够通过问题中提供的代码连接到模拟器的人。 It is not clear in the Firestore C# documentation. Firestore C# 文档中并不清楚。

    string project = ConfigurationManager.AppSettings["firestore_projectid"];
    Environment.SetEnvironmentVariable("FIRESTORE_EMULATOR_HOST", "localhost:8080");
    FirestoreDb db = new FirestoreDbBuilder
        {
            ProjectId = project,
            EmulatorDetection = Google.Api.Gax.EmulatorDetection.EmulatorOnly
              
        }.Build();

it seems that c# is not supported by the firebase emulator. firebase 仿真器似乎不支持 c#。 check here:在这里检查:

https://firebase.google.com/docs/emulator-suite#feature-matrix https://firebase.google.com/docs/emulator-suite#feature-matrix

for admin sdk just Nodejs对于管理员 sdk 只是 Nodejs

I've adding this validation to determine the environment involved (dev or prod):我已添加此验证以确定所涉及的环境(开发或产品):

if (builder.Environment.IsDevelopment())
{
    Environment.SetEnvironmentVariable("FIRESTORE_EMULATOR_HOST", "localhost:8080");
    builder.Services.AddSingleton(_ => new FirestoreProvider(
        new FirestoreDbBuilder
        {
            ProjectId = "your project id",
            EmulatorDetection = Google.Api.Gax.EmulatorDetection.EmulatorOnly
        }.Build()
        ));
}
else
{
    Environment.SetEnvironmentVariable("FIRESTORE_EMULATOR_HOST", "");
    builder.Services.AddSingleton(_ => new FirestoreProvider(
       new FirestoreDbBuilder
       {
           ProjectId = "your project id",
           JsonCredentials = "your json config",
       }.Build()
       ));
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM