在Windows和Linux上安装MongoDB

In the previous tutorial, we have learnt about Introduction, Overview, Advantages, Features and when to use MongoDB. In this tutorial we will learn how to setup MongoDB in our local machines. We will be covering steps to install MongoDB and related tools on Windows operating system and Linux operating system.

在上一教程中,我们了解了简介,概述,优势,功能以及何时使用MongoDB。 在本教程中,我们将学习如何在本地计算机上设置MongoDB。 我们将介绍在Windows操作系统和Linux操作系统上安装MongoDB和相关工具的步骤。

在Windows上安装MongoDB (Installing MongoDB on Windows)

Installing MongoDB on a Windows machine is very easy. Below are the steps involved in installing the MongoDB:

在Windows计算机上安装MongoDB非常容易。 以下是安装MongoDB涉及的步骤:

  1. Download MongoDB executable .msi file from the site MongoDB Download Centre. Select the latest version for Windows, the Windows Server 2008 R2 is the version if you are on Windows 7, 8 or 10.

    从站点MongoDB下载中心下载MongoDB可执行文件.msi文件。 选择Windows的最新版本,如果您使用的是Windows 7、8或10,则为Windows Server 2008 R2。

    Installing MongoDB on Windows
  2. Double click the downloaded .msi file to start the installation. Select the option Custom during the installation process, to specify a custom location where you want MongoDB to be installed. By default it is installed in C:\mongodb directory.

    双击下载的.msi文件开始安装。 在安装过程中选择选项“ 自定义 ”,以指定要在其上安装MongoDB的自定义位置。 默认情况下,它安装在C:\mongodb目录中。

  3. Once the installation is successful, the below directory structure is created. We have installed our MongoDB in D:\java\mongodb

    安装成功后,将创建以下目录结构。 我们已经在D:\java\mongodb安装了MongoDB

    Installing MongoDB on Windows
  4. Navigate to the bin directory of the MongoDB to understand about the components used in MongoDB. Below are some of the vital components and files to run them:

    导航到MongoDB的bin目录,以了解MongoDB中使用的组件。 以下是一些运行它们的重要组件和文件:

    Component.exe File
    Servermongod.exe
    Routermongos.exe
    Clientmongo.exe
    零件 .exe文件
    服务器 蒙哥德
    路由器 蒙哥斯
    客户 蒙哥
  5. It is required to set up the MongoDB environment. MongoDB stores all its data under the folder data\db. It is best practice to create this directory under the folder where the MongoDB is installed. So let's create a folder named data and one more folder named db inside data folder as shown below.

    需要设置MongoDB环境。 MongoDB将其所有数据存储在文件夹data\db 。 最佳实践是在安装MongoDB的文件夹下创建此目录。 因此,让我们在data文件夹内创建一个名为data的文件夹和一个名为db的文件夹,如下所示。

    Installing MongoDB on Windows
  6. Also create a log folder to log the MongoDB data transactions. Under the log folder, create a log file FILE_NAME.log.

    还创建一个日志文件夹来记录MongoDB数据事务。 在日志文件夹下,创建一个日志文件FILE_NAME.log

  7. Now, to verify whether the installation is successful or not, open the command prompt and navigate to the bin directory of the MongoDB installed folder.

    现在,要验证安装是否成功,请打开命令提示符并导航到MongoDB已安装文件夹的bin目录。

  8. Execute the command mongod.exe --dbpath "DATA_DIRECTORY_PATH" to configure the data path and start the MongoDB server. Please replace the DATA_DIRECTORY_PATH with the path of data directory present inside MongoDB installed folder. On running this command, the below log will be displayed which says that the MongoDB configuration is successful and the server is up and running fine.

    执行命令mongod.exe --dbpath "DATA_DIRECTORY_PATH"来配置数据路径并启动MongoDB服务器。 请使用MongoDB安装文件夹中存在的数据目录路径替换DATA_DIRECTORY_PATH 。 运行此命令时,将显示以下日志,该日志指示MongoDB配置成功并且服务器已启动且运行良好。

    Installing MongoDB on Windows
  9. Now, open another command prompt window and navigate to the bin directory of the MongoDB again, and start the MongoDB client in order to use the database system. Run the command mongo in Command Prompt and it will get connected to the MongoDB where the default database is test.

    现在,打开另一个命令提示符窗口,并再次导航到MongoDB的bin目录,然后启动MongoDB客户端以使用数据库系统。 在命令提示符中运行命令mongo ,它将连接到默认数据库为test的MongoDB。

    Installing MongoDB on Windows
  10. With this, we have successfully installed the MongoDB on the windows environment and we are good to start off with the MongoDB.

    这样,我们已经在Windows环境中成功安装了MongoDB,并且很高兴从MongoDB开始。

翻译自: https://www.studytonight.com/mongodb/setup-mongodb

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值