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

本文是小编为大家收集整理的关于Mongodb-运行 "mongo "和 "mongod "数据库之间的区别的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

所以,我敢肯定我在这里缺少一些简单的东西,但是当我以守护程序(使用mongod- fork或仅仅是mongod)运行mongo时,我看到的数据库内容与刚刚在" mongo"上运行的数据库内容不同主机.

我唯一的假设是,当数据仅运行外壳时,数据被存储在/数据/db以外的地方,然后在启动Mongod时切换到/DATA/DB.在这种情况下,我如何在运行Mongod时获取数据?

推荐答案

我认为这里有些混乱.

mongod是" mongo守护程序",基本上是数据库的主机过程.当您开始mongod时,您基本上是在说"启动mongodb进程并在后台运行" . mongod有几个默认参数,例如将数据存储在/data/db中,并在端口27017上运行.

mongo是连接到mongod特定实例的命令行壳.当您在没有参数的情况下运行mongo时,它默认将连接到端口27017上的localhost.如果您对无效的机器运行mongo,则端口组合将无法连接(并告诉您尽可能多).

理想情况下,除了"周围玩"以外,您将使用命令行参数用于启动mongod.通过相同的措施,您应该使用明确的说明开始mongo外壳.

根据您的描述,我认为您可能会遇到有关使用默认数据库的问题.尝试使用以下内容启动mongo(其中dbname是您的数据库名称)

./mongo localhost:27017/dbname

其他推荐答案

是的,这可能是对这个问题的幼稚答案,但我正在提出它,以便人们可以轻松理解它!

mongod:

mongod

(Mongo Daemon的缩写)是MongoDB服务器使用的背景过程来完成工作.此过程负责管理整个MongoDB服务器任务,例如接受请求,响应用户,管理MongoDB服务器操作的内存要求以及MongoDB服务器运行必不可少的其他内容.

tldr; 基本上是mongodb服务器

mongo:

mongo

另一方面,是MongoDB的交互式JavaScript Shell接口,该接口为系统管理员提供了强大的接口,也为开发人员直接使用数据库测试查询和操作的方式. Mongo还提供了一个功能齐全的JavaScript环境,可用于MongoDB

tldr; 基本上我认为它是mongodb客户端,可以用作shell访问mongoDB数据库服务器运行我的mongod Instances

其他推荐答案

mongo D(守护程序过程). 用简单的" Hello World"单词 - 您不会直接传达Mongod. 相反,您使用 db客户端:

您找到了更多类似的工具.

在您的情况下,您要使用 mongo shell client(mongo命令).

Visual

看到"客户" - "在行动中"的好方法是并排打开两个终端(或更多).

run mongod(如果没有MongoDB服务器安装和运行,mongo命令将无法正常工作),然后运行mongo:

在此处输入图像说明

输出(1 connection: application mongo shell} 在这里输入图像说明

接下来,运行一些 crud 操作并在mongod下查看消息./p>

相同的想法,如果您连接 Compass Client : 在这里输入图像说明

管理mongoDB流程文档(更改数据目录,端口等): https://www.mongodb.com/docs/docs/docs/manual/tutorial/管理MongoDB程序/

本文地址:https://www.itbaoku.cn/post/597538.html

问题描述

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

其他推荐答案

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.

TLDR; Basically it is the MongoDB server

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

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

其他推荐答案

MongoD(Daemon process). In simple "Hello world" words - You won't communicate Mongod directly. Instead, you use DB client:

And you find more tools like this.

In your case, you want to use Mongo Shell client (mongo command).

Visual

A great way to see "the client" - "in action" is to open two terminals (or more) side by side.

Run mongod (mongo command will not work without MongoDB server install and running), then run mongo:

enter image description here

Output (1 connection: application mongo shell} enter image description here

Next, run some CRUD Operations and see the messages under mongod.

Same idea if you connect Compass client: enter image description here

Manage mongodb processes docs (Change data directory, Port and so on): https://www.mongodb.com/docs/manual/tutorial/manage-mongodb-processes/