Google Datastore仍然指向App Engine生产数据库而不是本地模拟器

时间:2017-10-30 20:04:09

标签: node.js google-app-engine google-cloud-datastore

我有一个本地NodeJS应用程序,我正在本地构建。

我希望本地应用程序指向本地数据存储模拟器(而不是生产云数据存储区)。

我按照此页面上的说明操作...但是,应用程序仍然指向CLOUD数据存储区(而不是我的本地数据存储区)。我确认了这一点,因为数据显示在App Engine的数据存储区实体页面中。

根据此页面,https://cloud.google.com/datastore/docs/tools/datastore-emulator所有应该要求的是通过运行此命令来设置环境变量:

$(gcloud beta emulators datastore env-init)

我确认环境变量设置正确。为什么我的应用程序仍然指向Cloud Datastore而不是本地模拟器?

myusername$ $(gcloud beta emulators datastore env-init)
myusername$ gcloud beta emulators datastore env-init
export DATASTORE_DATASET=projectname
export DATASTORE_EMULATOR_HOST=localhost:8081
export DATASTORE_EMULATOR_HOST_PATH=localhost:8081/datastore
export DATASTORE_HOST=http://localhost:8081
export DATASTORE_PROJECT_ID=projectname

以下是运行模拟器时的输出:

myname$ gcloud beta emulators datastore start
WARNING: Reusing existing data in [/Users/myname/.config/gcloud/emulators/datastore].
Executing: /Users/myname/google-cloud-sdk/platform/cloud-datastore-emulator/cloud_datastore_emulator start --host=localhost --port=8081 --store_on_disk=True --consistency=0.9 --allow_remote_shutdown /Users/myname/.config/gcloud/emulators/datastore
[datastore] Oct 30, 2017 3:47:46 PM com.google.cloud.datastore.emulator.CloudDatastore$FakeDatastoreAction$8 apply
[datastore] INFO: Provided --allow_remote_shutdown to start command which is no longer necessary.
[datastore] Oct 30, 2017 3:47:46 PM com.google.cloud.datastore.emulator.impl.LocalDatastoreFileStub <init>
[datastore] INFO: Local Datastore initialized:
[datastore]     Type: High Replication
[datastore]     Storage: /Users/myname/.config/gcloud/emulators/datastore/WEB-INF/appengine-generated/local_db.bin
[datastore] Oct 30, 2017 3:47:47 PM com.google.cloud.datastore.emulator.impl.LocalDatastoreFileStub load
[datastore] INFO: The backing store, /Users/myname/.config/gcloud/emulators/datastore/WEB-INF/appengine-generated/local_db.bin, does not exist. It will be created.
[datastore] Oct 30, 2017 3:47:47 PM io.gapi.emulators.netty.NettyUtil applyJava7LongHostnameWorkaround
[datastore] INFO: Unable to apply Java 7 long hostname workaround.
[datastore] API endpoint: http://localhost:8081
[datastore] If you are using a library that supports the DATASTORE_EMULATOR_HOST environment variable, run:
[datastore] 
[datastore]   export DATASTORE_EMULATOR_HOST=localhost:8081
[datastore] 
[datastore] Dev App Server is now running.
[datastore] 

1 个答案:

答案 0 :(得分:0)

我发现设置DATASTORE_EMULATOR_HOSTDATASTORE_PROJECT_ID就足够了。

也许它正在寻找指向云的其他环境变量?

您是否尝试过清除GOOGLE_APPLICATION_CREDENTIALS环境变量?