Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google cloud platform Can';t从Google函数连接到MongoDB Atlas_Google Cloud Platform_Google Cloud Functions_Mongodb Atlas - Fatal编程技术网

Google cloud platform Can';t从Google函数连接到MongoDB Atlas

Google cloud platform Can';t从Google函数连接到MongoDB Atlas,google-cloud-platform,google-cloud-functions,mongodb-atlas,Google Cloud Platform,Google Cloud Functions,Mongodb Atlas,我已经在appengine上安装了一个express服务器,它正在使用我的Mongo Atlas数据库,一切都很好 我想启动一个云函数,它使用相同的数据库并处理pubsub事件。但是,部署函数时无法连接到数据库 我尝试使用私有URI和公共URI。对于公众,我有时会设法连接,但并非总是这样(而且我必须使集群上的所有IP都保持最白色) 这是功能代码(简化) 我在GAE上的Express应用程序上使用相同的连接字符串 我激活了VPC无服务器,并在Mongo Atlas上列出了IP范围。 Mongo A

我已经在appengine上安装了一个express服务器,它正在使用我的Mongo Atlas数据库,一切都很好

我想启动一个云函数,它使用相同的数据库并处理pubsub事件。但是,部署函数时无法连接到数据库

我尝试使用私有URI和公共URI。对于公众,我有时会设法连接,但并非总是这样(而且我必须使集群上的所有IP都保持最白色)

这是功能代码(简化)

我在GAE上的Express应用程序上使用相同的连接字符串

我激活了VPC无服务器,并在Mongo Atlas上列出了IP范围。 Mongo Atlas和GCP之间的对等已启动并运行

我得到的错误是:

A 2020-08-18T09:16:03.547Z scenarioManager-staging Error while DB connecting scenarioManager-staging  
A 2020-08-18T09:16:03.547Z scenarioManager-staging { MongooseServerSelectionError: Could not connect to any servers in your MongoDB Atlas cluster. One common reason is that you're trying to access the database from an IP that isn't whitelisted. Make sure your current IP address is on your Atlas cluster's IP whitelist: https://docs.atlas.mongodb.com/security-whitelist/ scenarioManager-staging  
A 2020-08-18T09:16:03.547Z scenarioManager-staging     at NativeConnection.Connection.openUri (/workspace/node_modules/mongoose/lib/connection.js:830:32) scenarioManager-staging  
A 2020-08-18T09:16:03.547Z scenarioManager-staging     at Mongoose.connect (/workspace/node_modules/mongoose/lib/index.js:335:15) scenarioManager-staging  
A 2020-08-18T09:16:03.547Z scenarioManager-staging     at Object.<anonymous> (/workspace/smsGateway.js:16:10) scenarioManager-staging  
A 2020-08-18T09:16:03.547Z scenarioManager-staging     at Module._compile (internal/modules/cjs/loader.js:778:30) scenarioManager-staging  
A 2020-08-18T09:16:03.547Z scenarioManager-staging     at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10) scenarioManager-staging  
A 2020-08-18T09:16:03.547Z scenarioManager-staging     at Module.load (internal/modules/cjs/loader.js:653:32) scenarioManager-staging  
A 2020-08-18T09:16:03.547Z scenarioManager-staging     at tryModuleLoad (internal/modules/cjs/loader.js:593:12) scenarioManager-staging  
A 2020-08-18T09:16:03.547Z scenarioManager-staging     at Function.Module._load (internal/modules/cjs/loader.js:585:3) scenarioManager-staging  
A 2020-08-18T09:16:03.547Z scenarioManager-staging     at Module.require (internal/modules/cjs/loader.js:692:17) scenarioManager-staging  
A 2020-08-18T09:16:03.547Z scenarioManager-staging     at require (internal/modules/cjs/helpers.js:25:18) scenarioManager-staging  
A 2020-08-18T09:16:03.547Z scenarioManager-staging     at Object.<anonymous> (/workspace/index.js:1:20) scenarioManager-staging  
A 2020-08-18T09:16:03.547Z scenarioManager-staging     at Module._compile (internal/modules/cjs/loader.js:778:30) scenarioManager-staging  
A 2020-08-18T09:16:03.547Z scenarioManager-staging     at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10) scenarioManager-staging  
A 2020-08-18T09:16:03.547Z scenarioManager-staging     at Module.load (internal/modules/cjs/loader.js:653:32) scenarioManager-staging  
A 2020-08-18T09:16:03.547Z scenarioManager-staging     at tryModuleLoad (internal/modules/cjs/loader.js:593:12) scenarioManager-staging  
A 2020-08-18T09:16:03.547Z scenarioManager-staging     at Function.Module._load (internal/modules/cjs/loader.js:585:3) scenarioManager-staging  
A 2020-08-18T09:16:03.547Z scenarioManager-staging   message: scenarioManager-staging  
A 2020-08-18T09:16:03.547Z scenarioManager-staging    'Could not connect to any servers in your MongoDB Atlas cluster. One common reason is that you\'re trying to access the database from an IP that isn\'t whitelisted. Make sure your current IP address is on your Atlas cluster\'s IP whitelist: https://docs.atlas.mongodb.com/security-whitelist/', scenarioManager-staging  
A 2020-08-18T09:16:03.547Z scenarioManager-staging   reason: scenarioManager-staging  
A 2020-08-18T09:16:03.547Z scenarioManager-staging    TopologyDescription { scenarioManager-staging  
A 2020-08-18T09:16:03.547Z scenarioManager-staging      type: 'ReplicaSetNoPrimary', scenarioManager-staging  
A 2020-08-18T09:16:03.547Z scenarioManager-staging      setName: null, scenarioManager-staging  
A 2020-08-18T09:16:03.547Z scenarioManager-staging      maxSetVersion: null, scenarioManager-staging  
A 2020-08-18T09:16:03.547Z scenarioManager-staging      maxElectionId: null, scenarioManager-staging  
A 2020-08-18T09:16:03.547Z scenarioManager-staging      servers: scenarioManager-staging  
A 2020-08-18T09:16:03.547Z scenarioManager-staging       Map { scenarioManager-staging  
A 2020-08-18T09:16:03.547Z scenarioManager-staging         '*-shard-00-00-pri.xgtnk.gcp.mongodb.net:27017' => [ServerDescription], scenarioManager-staging  
A 2020-08-18T09:16:03.547Z scenarioManager-staging         '*-shard-00-01-pri.xgtnk.gcp.mongodb.net:27017' => [ServerDescription], scenarioManager-staging  
A 2020-08-18T09:16:03.547Z scenarioManager-staging         '*-shard-00-02-pri.xgtnk.gcp.mongodb.net:27017' => [ServerDescription] }, scenarioManager-staging  
A 2020-08-18T09:16:03.547Z scenarioManager-staging      stale: false, scenarioManager-staging  
A 2020-08-18T09:16:03.547Z scenarioManager-staging      compatible: true, scenarioManager-staging  
A 2020-08-18T09:16:03.548Z scenarioManager-staging      compatibilityError: null, scenarioManager-staging  
A 2020-08-18T09:16:03.548Z scenarioManager-staging      logicalSessionTimeoutMinutes: null, scenarioManager-staging  
A 2020-08-18T09:16:03.548Z scenarioManager-staging      heartbeatFrequencyMS: 10000, scenarioManager-staging  
A 2020-08-18T09:16:03.548Z scenarioManager-staging      localThresholdMS: 15, scenarioManager-staging  
A 2020-08-18T09:16:03.548Z scenarioManager-staging      commonWireVersion: null } } scenarioManager-staging  

你能帮我吗

[编辑] 我在默认VPC上添加了一个防火墙条目,以允许27015-2017出站。 我在服务帐户上添加了访问网络的权限。
.. 但仍然是在私人领域。在公共应用程序中,如果有完整的白名单,我有时会连接,但不总是这样。

尝试在本地运行该功能,并确保它工作正常


如果它在本地工作而不是在部署后工作,请确保您的firebase项目升级到
Blaze
计划。

尝试在本地运行该功能并确保它工作


如果它在本地工作,而不是在部署后工作,请确保您的firebase项目升级到
Blaze
计划。

在查看它时,我发现此处报告了一个类似的问题[1]。使用Google DNS解决了用户的问题。如果有帮助的话,我建议检查这个链接


[1]

在调查过程中,我发现了此处报告的类似问题[1]。使用Google DNS解决了用户的问题。如果有帮助的话,我建议检查这个链接


[1]

我使用完整的本地配置(pubsub+函数+数据库)完成了开发。我刚从我的电脑上测试了与Mongo Atlas的连接,效果很好

$ functions-framework --target=scenarioManagerPushPubSub --signature-type=event --source=./scenarioManager.js
Serving function...
Function: scenarioManagerPushPubSub
URL: http://localhost:8080/
Connected to mongoDB
scenarioManager :  { call: '5f3a39ec79c84c000a063802' } Object
Call  5f3a39ec79c84c000a063802  found
Nothing to do for this scenario 5f353c0319947a000afe9bde

我用一个完整的本地配置(pubsub+函数+数据库)完成了开发。我刚从我的电脑上测试了与Mongo Atlas的连接,效果很好

$ functions-framework --target=scenarioManagerPushPubSub --signature-type=event --source=./scenarioManager.js
Serving function...
Function: scenarioManagerPushPubSub
URL: http://localhost:8080/
Connected to mongoDB
scenarioManager :  { call: '5f3a39ec79c84c000a063802' } Object
Call  5f3a39ec79c84c000a063802  found
Nothing to do for this scenario 5f353c0319947a000afe9bde

由于都在GCP上,我无法管理DNS配置。我的群集不在固定IP上。因为它都在GCP上,所以我无法管理DNS配置。我的群集不在固定IP上。
$ functions-framework --target=scenarioManagerPushPubSub --signature-type=event --source=./scenarioManager.js
Serving function...
Function: scenarioManagerPushPubSub
URL: http://localhost:8080/
Connected to mongoDB
scenarioManager :  { call: '5f3a39ec79c84c000a063802' } Object
Call  5f3a39ec79c84c000a063802  found
Nothing to do for this scenario 5f353c0319947a000afe9bde