我正在尝试从Ruby脚本,最终从Rails应用程序中读写Firestore数据库。
这似乎是一项琐碎的任务,但当我在IRB中运行测试脚本时,它不会让我写入或读取数据。
我试过:
google-cloud-firestore 创业板require 'google/cloud/firestore' # => true
# credentials
cred = Google::Cloud::Firestore::Credentials.new('<path/to/my/keyfile/key-projectname-etc.json>')
# => #<Google::Cloud::Firestore::Credentials:...>
# initialize firestore connection
db = Google::Cloud::Firestore.new(
project_id: '<MY-PROJECT-ID>',
credentials: cred
) # => #<Google::Cloud::Firestore::Client:...>
# write a document inside the users collection
db.doc("users/helloFromRuby").set({ name: "yay it worked!"})这是我得到的错误消息:
Google::Cloud::UnavailableError (14:failed to connect to all addresses)发布于 2019-07-20 20:40:41
我可以解决我的问题:我初始化了一个环境变量GOOGLE_APPLICATION_CREDENTIALS,它以某种方式干扰了我的json密钥文件。删除那个变量解决了我的问题。
https://stackoverflow.com/questions/57101015
复制相似问题