如何使用URL Fetch服务用Mongodb替换弃用的ScriptDb? [英] How to replace the deprecated ScriptDb with Mongodb using URL Fetch service?

查看:142
本文介绍了如何使用URL Fetch服务用Mongodb替换弃用的ScriptDb?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于最近ScriptDb 弃用,我需要将其替换。我选择了MongoDb(因为我需要noSQL db)。 Google不提供关于如何连接mongo的任何指南。只是说应该使用 mongolab

我在mongolab上创建了一个数据库。他们给了我以下连接方式:

 使用shell进行连接:
mongo ds045679.mongolab。 com:45679 / prjacc -u< dbuser> -p< dbpassword>
使用驱动程序通过标准URI进行连接(这是什么?):
mongodb://< dbuser>:< dbpassword> @ ds045679.mongolab.com:45679 / prjacc

但是没有google脚本的驱动程序
,所以我无法弄清楚如何替换旧的代码:

  var db = ScriptDb.getMyDb(); 
//使用db ...

使用URL Fetch Service访问mongo。



任何帮助表示感谢!

解决方案

我们找到了解决方案。
MongoDB也提供了访问数据库的第三种方式,尽管他们强烈建议使用我的问题中描述的两种方式。这是使用他们的REST API:




所以我们应该通过这个URL https://api.mongolab.com/api/1/databases?apiKey= < code> UrlFetchApp.fetch()函数




Due to the recent ScriptDb deprecation I need to replace it. I chose MongoDb(as I need noSQL db). Google does not provide any guides on how to connect mongo. It's just said that one should use mongolab and URL Fetch service.

I created a data base on mongolab. They gave me the following ways of connecting to it:

To connect using the shell:
   mongo ds045679.mongolab.com:45679/prjacc -u <dbuser> -p <dbpassword>
To connect using a driver via the standard URI (what's this?):
   mongodb://<dbuser>:<dbpassword>@ds045679.mongolab.com:45679/prjacc

But there's no driver for google script so I can't figure out how to replace my old code:

var db = ScriptDb.getMyDb();
// work with db...

with access to mongo using URL Fetch Service.

Any help is appreciated!

解决方案

It seems that I've found a solution. MongoDB also provides the third way of accessing the DB, though they strongly recommend to use 2 ways described in my question. This is to use their REST API:

So it seems we should pass this url https://api.mongolab.com/api/1/databases?apiKey=<your-api-key> to the UrlFetchApp.fetch() function.

Please correct me if I'm not right. Any additions and notes are appreciated.

这篇关于如何使用URL Fetch服务用Mongodb替换弃用的ScriptDb?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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