从本地连接到真正的数据存储 [英] Connect to real datastore from local

查看:87
本文介绍了从本地连接到真正的数据存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的nodejs目录看起来像这样:

  MyApp 
-app.js
-mycredetnials.json
-package.json
+ node_modules

我的app.js文件我有以下代码:

  var options = {
projectId:'mydatastoreproject'
}

var keyFile ='./mydatastoreprojectsandbox-5265e25422c.json';

if(keyFile){
options.keyFilename = keyFile;
}

var datastore = gcloud.datastore(options);

我从本地计算机上运行此程序。我希望我的本地计算机能够连接到Google Cloud Datastore(而不是本地模拟器)。

在我的开发者控制台中,我启用了Google Datastore API。我在开发者控制台中创建了一个KIND并创建了一个实体。我还以json文件的形式创建了凭据(服务帐户密钥)。然后我将这个json文件包含在我的代码中。通过这样做,我仍然无法连接到数据存储。我错过了什么或做错了什么?基本上,我想要做的就是让我的本地机器连接到Google数据存储。 当您启动本地数据存储时,它打印出设置这些环境变量,你做到了吗?那到目前为止,你是如何连接到本地数据存储的?默认情况下,gcloud-node会尝试与远程API对话并假定没有模拟器在运行。必须告诉它与模拟器交谈,这可以通过env var( DATASTORE_EMULATOR_HOST )完成。如果这是您设置的内容,您将不得不取消设置(或者从JS脚本手动执行它: delete process.env.DATASTORE_EMULATOR_HOST; )。 p>

(完整答案: https:// github.com/GoogleCloudPlatform/gcloud-node/issues/1328


I have my nodejs directory which looks something like this:

MyApp
    -app.js
    -mycredetnials.json
    -package.json
    +node_modules

Inside of my app.js file I have the following code:;

var options = {
    projectId: 'mydatastoreproject'
}

var keyFile = './mydatastoreprojectsandbox-5265e25422c.json';

if (keyFile) {
  options.keyFilename = keyFile;
}

var datastore = gcloud.datastore(options);

I am running this from my local computer. I want my local computer to be able to connect to the Google Cloud Datastore (not the local emulator).

In my developer console I have enabled Google Datastore API. I created a KIND in the developer console and created one entity. I have also created credentials (service account key) in the form of a json file. I then included this json file in my code. By doing this I am still unable to connect to the datastore. Am I missing something or doing something wrong? Essentially all I want to do is to have my local machine connect to the Google Datastore.

解决方案

When you start the local datastore and it prints out "Set these environment variables", did you do that? Is that how you've been connecting to your local Datastore so far? By default, gcloud-node tries to talk to the remote API and assumes there is no emulator running. It has to be told to talk to the emulator, which can be done via the env var (DATASTORE_EMULATOR_HOST). If that is what you've been setting, you will have to unset it (or manually do it from the JS script: delete process.env.DATASTORE_EMULATOR_HOST;).

(Full answer: https://github.com/GoogleCloudPlatform/gcloud-node/issues/1328)

这篇关于从本地连接到真正的数据存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆