js with express.js app, i deployed it to appfog but i´m not able or i don´t know how to connect my mongodb collections located on MongoHQ to my AppFog mongodb service.
js with express.js app,我将它部署到appfog但是我不能或者我不知道如何将我在MongoHQ上的mongodb集合连接到我的AppFog mongodb服务。
MongoHQ provides you a mongo URI like:
MongoHQ为您提供了一个mongo URI,如:
mongodb://<user>:<password>@<hostname>:<port>/<databasename>
AppFog mongodb service provides you a environment variable called VCAP_SERVICE that contains all conf variables to connect your app to mongodb, but in the other hand i have my mongodb collections located on MongoHQ and i don´t know how to specify this MongoURI to my mongodb service on AppFog.
AppFog mongodb服务为您提供了一个名为VCAP_SERVICE的环境变量,其中包含将您的应用程序连接到mongodb的所有conf变量,但另一方面我将我的mongodb集合放在MongoHQ上,我不知道如何将此MongoURI指定给我的mongodb服务在AppFog上。
Hope you understand me, regards.
希望你理解我,问候。
1 个解决方案
#1
1
If I understand correctly, there might be two ways to solve your problem. Firstly, you may enable the MongoHQ add-on and AppFog will create a MongoHQ sandbox for you. You can get the MongoHQ URL by:
如果我理解正确,可能有两种方法可以解决您的问题。首先,您可以启用MongoHQ插件,AppFog将为您创建MongoHQ沙箱。您可以通过以下方式获取MongoHQ网址:
if(process.env.VCAP_SERVICES){
var env = JSON.parse(process.env.VCAP_SERVICES);
var mongo = env['MONGOHQ_URL'];
}
Since you said you have already got mongodb collections, you can clone your original collections to the one offered by AppFog via MongoHQ Web UI.
既然你说你已经有了mongodb集合,你可以将你的原始集合克隆到AppFog通过MongoHQ Web UI提供的集合。
The other solution is don't worry about the MongoHQ add-on in AppFog. Just directly connect to MongoHQ (I use mongoose, but native driver should do the similar thing):
另一个解决方案是不要担心AppFog中的MongoHQ插件。只是直接连接到MongoHQ(我使用mongoose,但本机驱动程序应该做类似的事情):
mongoose.connect(YOUR_MONGOHQ_URL);
Actually I got a similar problem recently and I successfully deploy my nodejs+express app to Heroku using this method. I was not bothered to enable the mongohq add-on in Heroku since I have already got a MongoDB sandbox.
实际上我最近遇到了类似的问题,我使用这种方法成功地将我的nodejs + express app部署到了Heroku。因为我已经有了一个MongoDB沙箱,所以我不想在Heroku中启用mongohq附加组件。
UPDATE I recently deployed a couple of applications in Heroku using mongodb native driver and monk to connect to a sandbox in MongoHQ. The code looks like:
更新我最近使用mongodb本机驱动程序和monk在Heroku中部署了几个应用程序,以连接到MongoHQ中的沙箱。代码如下:
var monk=require('monk');
var db=monk("mongodb://username:pwd@sth.mongohq.com:port/YOURDB");
#1
1
If I understand correctly, there might be two ways to solve your problem. Firstly, you may enable the MongoHQ add-on and AppFog will create a MongoHQ sandbox for you. You can get the MongoHQ URL by:
如果我理解正确,可能有两种方法可以解决您的问题。首先,您可以启用MongoHQ插件,AppFog将为您创建MongoHQ沙箱。您可以通过以下方式获取MongoHQ网址:
if(process.env.VCAP_SERVICES){
var env = JSON.parse(process.env.VCAP_SERVICES);
var mongo = env['MONGOHQ_URL'];
}
Since you said you have already got mongodb collections, you can clone your original collections to the one offered by AppFog via MongoHQ Web UI.
既然你说你已经有了mongodb集合,你可以将你的原始集合克隆到AppFog通过MongoHQ Web UI提供的集合。
The other solution is don't worry about the MongoHQ add-on in AppFog. Just directly connect to MongoHQ (I use mongoose, but native driver should do the similar thing):
另一个解决方案是不要担心AppFog中的MongoHQ插件。只是直接连接到MongoHQ(我使用mongoose,但本机驱动程序应该做类似的事情):
mongoose.connect(YOUR_MONGOHQ_URL);
Actually I got a similar problem recently and I successfully deploy my nodejs+express app to Heroku using this method. I was not bothered to enable the mongohq add-on in Heroku since I have already got a MongoDB sandbox.
实际上我最近遇到了类似的问题,我使用这种方法成功地将我的nodejs + express app部署到了Heroku。因为我已经有了一个MongoDB沙箱,所以我不想在Heroku中启用mongohq附加组件。
UPDATE I recently deployed a couple of applications in Heroku using mongodb native driver and monk to connect to a sandbox in MongoHQ. The code looks like:
更新我最近使用mongodb本机驱动程序和monk在Heroku中部署了几个应用程序,以连接到MongoHQ中的沙箱。代码如下:
var monk=require('monk');
var db=monk("mongodb://username:pwd@sth.mongohq.com:port/YOURDB");