Accessing a MongoDB Atlas Cluster from within Google Cloud Functions Console

北城余情 提交于 2019-12-05 11:57:42

I had the exact same issue. It was failing for both MongoDB Atlas and mLab connections after running firebase deploy, but working locally using firebase serve.

I believe there are two problems:

  1. Outbound Networking is disabled on the free Spark plan. You have to upgrade to the Blaze Plan (pay-as-you-go) in order to do that. I just switched tiers and it works now.

The Spark plan allows outbound network requests only to Google-owned services. Inbound invocation requests are allowed within the quota. On the Blaze plan, Cloud Functions provides a perpetual free tier. The first 2,000,000 invocations, 400,000 GB-sec, 200,000 CPU-sec, and 5 GB of Internet egress traffic is provided for free each month. You are only charged on usage past this free allotment. Pricing is based on total number of invocations, and compute time. Compute time is variable based on the amount of memory and CPU provisioned for a function. Usage limits are also enforced through daily and 100s quotas. For more information, see Cloud Functions Pricing.

https://firebase.google.com/pricing/

You have to give a credit card, but as long as you remain under their data quota you don't get charged, apparently. I will try it out and see how it goes.

  1. After upgrading, your MongoDB Atlas connection might still be failing (while an mLab string would work). This is because your query URI is using the Mongo 3.6 SRV address, rather than the Mongo 3.4 driver's "mongodb://" protocol. Try switching the driver version and see if it works.

Try by issuing HTTP requests to query MongoDB. Cloud Functions allow only HTTP/S outbound traffic.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!