我试图通过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)
我可以解决我的问题:我GOOGLE_APPLICATION_CREDENTIALS
初始化了一个环境变量,以某种方式干扰了我的json密钥文件。删除该变量解决了我的问题。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句