绑定到Cloud Foundry后如何访问MongoDB值/数据? [英] How to access MongoDB values/data after binding to cloud foundry?

查看:93
本文介绍了绑定到Cloud Foundry后如何访问MongoDB值/数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Spring Boot,并使用mongodb数据库创建了一个Web应用程序。在本地,我使用命令提示符 mongod和 mongo在这里可以查询在UI中输入的数据。

I am using spring boot and created a web application using a mongodb database. Locally I use command prompt "mongod" and "mongo" where I can query the data that I have inputted in the UI.

我当前的应用程序使用的是在本地主机上运行的MongoDb默认端口为27017。我的Web应用程序反映了存储在数据库中的数据。当我将此应用程序推送到Cloud Foundry并绑定MONGODB服务时,它将使用另一个数据库。我在哪里以及如何查看/访问所有正在输入的数据。在本地计算机上,我可以使用db.collection.find()并查询我的所有数据。

My current application is using MongoDb running on localhost with default port 27017. My web application reflect the data that is stored in the database. When I push this application to cloud foundry, and bind the MONGODB service, it uses another database. Where and how can I view/access all the data that are being inputted. On the local machine I am able to use db.collection.find() and it queries all of my data.

问题

一旦我将应用程序推送到Cloud Foundry,我的所有数据本地存储的未与其链接。我能够将值存储到PCF MongoDB中。但是我不知道如何查看其中的数据。是否有命令或方法可以查看我输入到PCF MongoDB中的所有数据?

Once I push my application to cloud foundry, All my data that was stored locally is not linked with it. I am able to store values into PCF MongoDB. But I do not know how to view the data that I have in it. Is there a command or a method to view all the data that I have inputted into PCF MongoDB?

尝试

查看我的VCAP_SERVICES,我可以看到我的数据库名称,用户名和密码。但是它们看起来像是已加密,由字母数字和连字符混合而成。下面的示例显示VCAP的样子(副本值,相同格式)

Looking at my VCAP_SERVICES I was able to see my database name, username, and password. But they look like they are encrypted, it has letters numbers and hypens all mixed. Example below how VCAP looks like(replica values, same format)

"database": "9faf201a-39b1-4lse-49242f404g11"
"host": "10.100.100.333"
"password": "2jnkj4nk22kk5lk6kj4n4k6nkj6001"
"username": "401849301k-8g3f-5c3j-k28-583920308592f04"

我尝试在CLI中使用以下代码

I tried using the code below in a CLI

mongo someurl.mongodomain.com:45475/database_name -u username -p password

因此,对于数据库名称,用户名和密码,我只是复制并粘贴了加密的外观用户名和密码

So for databasename, username, and password I simply copied and pasted the encrypted looking username and password

mongo myurl.com:1337/9faf201a-39b1-4lse-49242f404g11 -u 401849301k-8g3f-5c3j-k28-583920308592f04" -p 2jnkj4nk22kk5lk6kj4n4k6nkj6001

我连接失败。也许我必须输入正确的用户名和密码。在哪里可以设置用户名和密码?我使用的是Spring Boot,它是为我自动处理的。 er创建了用户名或密码。

and I get a connection failed. Maybe I have to input the correct user name and password. Where can I set a username and password? I am using spring boot and it was automatically handled for me. So that, I never created a username or password.

推荐答案

以下是五个建议(感谢Daniel.Mikusa的最后一个建议):

Here are five suggestions (thanks to Daniel.Mikusa for the last one):

您可以通过与mongo客户程序连接的方式与远程mongodb连接的方式类似您当地的mongodb。您可以在应用程序的环境中找到凭据(用户名,密码,数据库名称):

You may be able to connect to the remote mongodb with the mongo client program in a similar way as you connect to your local mongodb. You can find the credentials (username, password, db-name) in the environment of your app:

cf env <your-app-name>

但是,在您的CloudFoundry安装范围之外的计算机上可能无法访问mongodb实例。在这种情况下,您可能要尝试下一个选项。

Access to the mongodb instance may, however, be blocked from machines outside of your CloudFoundry installation. In this case you may want to try the next option.

将已安装mongo客户端的docker容器推送到cloudfoundry。将ssh放入docker容器,然后从那里使用mongo客户端。在所有cloudfoundry安装中均未启用将Docker容器推送到CF。

Push a docker container that has the mongo client installed to cloudfoundry. Ssh into the docker container, and use the mongo client from there. Pushing docker containers to CF is not enabled in all cloudfoundry installations.

最后,您可以通过REST控制器公开域对象。可能使用spring数据休息: http://projects.spring.io/spring-data-rest /

Finally you could expose your domain objects via REST-Controllers. Possibly using spring data rest: http://projects.spring.io/spring-data-rest/.

使用 cf ssh 和ssh隧道。将mongodb实例绑定到应用程序,运行 cf env 以获取主机,端口和凭据(或创建服务密钥)。然后运行 cf ssh -N -L< localport>:< service-fqdn-or-ip>:< remote-port> app-name (您连接到的应用程序并不重要,它只是我们正在通过的应用程序)。现在将客户端连接到 localhost:< localport> 并使用从cf env获得的凭据。

Use cf ssh and an ssh tunnel. Bind the mongodb instance to an app, run cf env to get the host, port and credentials (or make a service key). Then run cf ssh -N -L <localport>:<service-fqdn-or-ip>:<remote-port> app-name (the app you connect to doesn't strictly matter, it's just the one we are tunneling through). Now connect a client to localhost:<localport> and use the credentials you got from cf env.

这篇关于绑定到Cloud Foundry后如何访问MongoDB值/数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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