使用Codeignator远程连接到MongoDB服务器 [英] Remote connection to MongoDB server using Codeigniter

查看:286
本文介绍了使用Codeignator远程连接到MongoDB服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用MongoDB和Codeigniter创建了一个API。我想使用IP地址(不工作)而不是使用localhost连接到我的数据库(工作正常)。因为我需要在一个单独的服务器上的MongoDB。

I am creating an API using MongoDB and Codeigniter. I want to connect to my database using an IP-address (not working) instead of using localhost (working fine). Because I need to have the MongoDB on a seperate server.

我试图只是从localhost更改为Codeigniter库的配置文件中的IP地址,

I tried to just change from localhost to the IP-address in the configuration file for the Codeigniter library but then I cannot connect.

我使用这个Ci MongoDB库: https://github.com/alexbilbie/codeigniter-mongodb-library

I am using this Ci MongoDB library: https://github.com/alexbilbie/codeigniter-mongodb-library

我该如何做?

推荐答案

我不是一个mongo db专家。但我可以肯定地说,你需要使用主机名的连接,而不是使用IP地址。

I am not a mongo db expert. But I could definitely say that you would need to use a host-name for the connections rather than using an ip-address.

问题的解决方案是将您的远程服务器的IP地址添加到hosts文件中。在ubuntu中,您可以在/ etc / hosts中找到它

The solution to the problem will be to add your remote server's ip address in the hosts file. In ubuntu, you could find it in /etc/hosts

编辑

10.xxx.xxx.xxx your-server-name

并保存

,那么你总是可以通过在你启动mongo db连接的语法中用your-server-name(你在主机中给出的)替换localhost来连接。

then you can always connect by replacing localhost with "your-server-name" (that you gave in hosts) in your syntax where you initiate your mongo db connection.

猜猜这可能不会帮助你,因为你会想到它已经。但可能会帮助正在寻找类似问题的人。

Guess this might not help you as you would have figured it out already. But might help someone who is searching for a similar question.

这篇关于使用Codeignator远程连接到MongoDB服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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