【问题标题】:How to fix Google Firestore issue in Elixir?如何解决 Elixir 中的 Google Firestore 问题?
【发布时间】:2019-08-29 00:19:12
【问题描述】:

我总是遇到问题,调用时:GoogleApi.Firestore.V1beta1.Api.Projects.firestore_projects_databases_documents_run_query(),如下图。

我已经尝试过不同的输入和格式化方式,以及不同的 Firestore 集合。

{:ok, token} = Goth.Token.for_scope("https://www.googleapis.com/auth/cloud-platform")

conn = GoogleApi.Firestore.V1beta1.Connection.new(token.token)

query = %GoogleApi.Firestore.V1beta1.Model.RunQueryRequest{
  structuredQuery: %{
    :from => %{:collectionId => "demo"},
    :limit => 1
  }
}

GoogleApi.Firestore.V1beta1.Api.Projects.firestore_projects_databases_documents_run_query(
  conn,
  "projects/demo/databases/(default)/documents",
  body: query
)

结果:

** (BadMapError) expected a map, got: [%{"readTime" => "2019-04-07T20:23:48.219664Z"}]
    (elixir) lib/map.ex:437: Map.get([%{"readTime" => "2019-04-07T20:23:48.219664Z"}], "document", nil)
    lib/poison/decoder.ex:53: anonymous fn/3 in Poison.Decode.transform_struct/4
    (stdlib) maps.erl:257: :maps.fold_1/3
    lib/poison/decoder.ex:52: Poison.Decode.transform_struct/4
    lib/poison.ex:70: Poison.decode/2

【问题讨论】:

  • 嗨@dominik,有趣的是我有同样的错误;无论如何,我开始使用您的示例来了解库是如何工作的,因为完全没有示例(即使在测试文件夹中:/)。

标签: google-cloud-platform google-cloud-firestore elixir


【解决方案1】:

对于它的价值,我已经设法通过执行以下操作来加载文档:

{:ok, token} = Goth.Token.for_scope("https://www.googleapis.com/auth/datastore")
conn = GoogleApi.Firestore.V1.Connection.new(token.token)
{:ok, document} = GoogleApi.Firestore.V1.Api.Projects.firestore_projects_databases_documents_get(
  conn,
  "projects/{project_id}/databases/(default)/documents/{collection_id}/{document_id}"
)

变量{XXX} 被替换为实际值。

也许不完全是您的用例,但由于很难找到在 Elixir 中使用 Firestore 的示例,这可能对某人有用!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-02
    • 1970-01-01
    • 2019-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多