在致电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
答案 0 :(得分: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的示例,因此这可能对某人有用!