database Mongodb - 运行“mongo”和“mongod”数据库的区别

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4883045/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 08:02:52  来源:igfitidea点击:

Mongodb - Difference between running "mongo" and "mongod" databases

mongodbshelldatabase

提问by Jesse

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.

所以,我确定我在这里遗漏了一些简单的东西,但是当我将 mongo 作为守护程序运行时(使用 mongod --fork 或仅使用 mongod),我看到的数据库内容与在主机上运行“mongo”不同.

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?

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

回答by Gates VP

I think there is some confusion here.

我认为这里有些混乱。

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

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

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

mongo是连接到mongod. 当您mongo不带参数运行时,它默认连接到端口 27017 上的本地主机。如果您mongo针对无效的 machine:port 组合运行,那么它将无法连接(并告诉您尽可能多的信息)。

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

理想情况下,除了“玩弄”之外,您还可以使用命令行参数启动mongod. 通过同样的措施,您应该mongo使用明确的指令启动shell。

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

根据您的描述,我认为您可能会遇到有关使用默认数据库的问题。尝试从mongo以下开始(dbname您的数据库名称在哪里)

./mongo localhost:27017/dbname

回答by Mr. Suryaa Jha

Yes, this might be a naive answer to this question but I am putting it forward so people can understand it easily!

是的,这可能是对这个问题的幼稚回答,但我提出来是为了让人们可以轻松理解!

Mongod:

蒙戈:

mongod

蒙哥

(Short for Mongo Daemon) is a background process used by MongoDB server to get things done. This process is responsible for managing the whole MongoDB server tasks such as accepting requests, responding to users, managing memory requirement of MongoDB server operations and other things essential for MongoDB Server to run.

(Mongo Daemon 的简称)是 MongoDB 服务器用来完成任务的后台进程。该进程负责管理整个 MongoDB 服务器的任务,例如接受请求、响应用户、管理 MongoDB 服务器操作的内存需求以及其他 MongoDB 服务器运行必不可少的事情。

TLDR;Basically it is the MongoDB server

TLDR;基本上它是MongoDB服务器

Mongo:

蒙哥:

Mongo

蒙戈

on the other hand, is an interactive JavaScript shell interface to MongoDB, which provides a powerful interface for system administrators as well as a way for developers to test queries and operations directly with the database. mongo also provides a fully functional JavaScript environment for use with a MongoDB

另一方面,是 MongoDB 的交互式 JavaScript shell 接口,它为系统管理员提供了一个强大的接口,也为开发人员提供了一种直接使用数据库测试查询和操作的方法。mongo 还提供了一个功能齐全的 JavaScript 环境,用于与 MongoDB 一起使用

TLDR;Basically I think it as mongodb client which can be used as a shell to get access to MongoDB database server run my mongod instances

TLDR;基本上我认为它是 mongodb 客户端,可以用作外壳来访问 MongoDB 数据库服务器运行我的 mongod 实例