Mongodb - 运行“mongo”之间的区别和“mongod”数据库 [英] Mongodb - Difference between running "mongo" and "mongod" databases

查看:2574
本文介绍了Mongodb - 运行“mongo”之间的区别和“mongod”数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我肯定我在这里缺少一些简单的东西,但是当我运行mongo作为守护进程(使用mongod --fork或只是mongod),我看到不同的数据库内容,如果我只是运行mongo主机。



我唯一的假设是,当数据只运行shell时,数据被存储在/ data / db以外的地方,并切换到/ data / db当我启动mongod。在这种情况下,如何在运行mongod时获取我的数据?

解决方案

p>

mongod 是Mongo Daemon,它基本上是数据库的主机进程。当你启动 mongod 时,你基本上是说启动MongoDB进程并在后台运行。 mongod 有多个默认参数,例如在 / data / db 中存储数据并在端口27017上运行。



mongo 是连接到 mongod 的特定实例的命令行shell $ c>。当你运行没有参数的 mongo 时,它默认连接到端口27017上的localhost。如果你运行 mongo 无效的机器:端口组合,然后它将无法连接(并告诉你多少)。



理想情况下,请使用命令行参数启动 mongod 。同样,你应该用明确的指令启动 mongo shell。



根据你的描述,可能遇到有关使用默认数据库的问题。尝试以下列方式启动 mongo (其中 dbname 是您的数据库名称)

  ./ mongo localhost:27017 / dbname 


So, I'm sure I'm missing something simple here, but when I run mongo as a daemon (using mongod --fork or just mongod), I see different database content than if I just run "mongo" on the host machine.

My only assumption is that the data is being stored somewhere other than /data/db when it's running just the shell, and switches to /data/db when I boot the mongod. In that case, how do I get at my data when running mongod?

解决方案

I think there is some confusion here.

mongod is the "Mongo Daemon" it's basically the host process for the database. When you start mongod you're basically saying "start the MongoDB process and run it in the background". mongod has several default parameters, such as storing data in /data/db and running on port 27017.

mongo is the command-line shell that connects to a specific instance of mongod. When you run mongo with no parameters it defaults to connecting to the localhost on port 27017. If you run mongo against an invalid machine:port combination then it will fail to connect (and tell you as much).

Ideally, when doing anything other than just "playing around", you'll use the Command Line Parameters for starting mongod. By the same measure you should start the mongo shell with explicit instructions.

Based on your description, I think you may be encountering an issue regarding the use of default databases. Try starting mongo with the following (where dbname is your database name)

./mongo localhost:27017/dbname

这篇关于Mongodb - 运行“mongo”之间的区别和“mongod”数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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