Cách tải xuống và cài đặt MongoDB on Windows và đám mây

⚡ Tóm tắt thông minh

Cách tải xuống và cài đặt MongoDB on Windows and Cloud is explained as a complete setup guide. This resource covers installing MongoDB Community Server on Windows, Các JavaKịch bản, Python, and Ruby drivers, MongoDB Compass, configuration with import and export, a config file, and deploying MongoDB Atlas on the cloud.

  • 🪟 Windows Cài đặt: Download the 64-bit Community Server and run the MSI installer.
  • 🔌 Trình điều khiển: JavaScript ships built in; add Python (pymongo) and Ruby (mongo) drivers.
  • 🧭 La bàn: cài đặt MongoDB Compass GUI to manage databases visually.
  • ⚙️ Cấu hình: Set the data directory, import/export CSV, and use a config file.
  • 🇧🇷 Đám mây: Triển khai MongoDB Atlas on AWS, Google Cloud, hoặc là Azure and connect a client.

Cách tải xuống và cài đặt MongoDB

Các trình cài đặt cho MongoDB are available in both the 32-bit and 64-bit format. The 32-bit installers are good for development and test environments. But for production environments you should use the 64-bit installers. Otherwise, you can be limited in the amount of data that can be stored within MongoDB. It is advisable to always use the stable release for production environments.

Cách tải xuống và cài đặt MongoDB on Windows

Các bước sau đây có thể được sử dụng để tải xuống và cài đặt MongoDB on Windows 10:

Bước 1) Tải xuống MongoDB Community Server

Tới liên kết này và tải xuống MongoDB Máy chủ cộng đồng. Chúng tôi sẽ cài đặt phiên bản 64-bit cho Windows.

Tải xuống cài đặt MongoDB on Windows

Bước 2) Nhấp vào Cài đặt

Once the download is complete, open the msi file. Click Next in the start-up screen.

Tải xuống cài đặt MongoDB on Windows

Bước 3) Chấp nhận Thỏa thuận cấp phép người dùng cuối

  1. Chấp nhận Thỏa thuận cấp phép người dùng cuối.
  2. Bấm tiếp.

Tải xuống cài đặt MongoDB on Windows

Step 4) Click on the “Complete” button

Click on the “Complete” button to install all of the components. The custom option can be used to install selective components or if you want to change the location of the installation.

Tải xuống cài đặt MongoDB on Windows

Bước 5) Cấu hình dịch vụ

  1. Select “Run service as Network Service user”. Make a note of the data directory; we will need this later.
  2. Bấm tiếp.

Tải xuống cài đặt MongoDB on Windows

Bước 6) Bắt đầu quá trình cài đặt

Bấm vào nút Cài đặt để bắt đầu cài đặt.

Tải xuống cài đặt MongoDB on Windows

Step 7) Click Next once completed

Installation begins. Click Next once completed.

Tải xuống cài đặt MongoDB on Windows

Bước 8) Nhấp vào nút Kết thúc

Final step: once the installation is complete, click on the Finish button.

Tải xuống cài đặt MongoDB on Windows

Xin chào thế giới MongoDB: JavaTrình điều khiển tập lệnh

Trình điều khiển ở MongoDB are used for connectivity between client applications and the database. For example, if you had a Java chương trình và yêu cầu nó kết nối với MongoDB, then you would require to download and integrate the Java trình điều khiển để chương trình có thể hoạt động với MongoDB cơ sở dữ liệu.

Người lái xe cho JavaScript ra khỏi hộp. MongoDB shell which is used to work with the MongoDB cơ sở dữ liệu thực sự là một JavaScript shell. To access it:

Bước 1) Go to “C:\Program Files\MongoDB\Server\4.0\bin” và nhấp đúp vào mongo.exe. Ngoài ra, bạn cũng có thể nhấp vào MongoDB desktop item.

Xin chào thế giới MongoDB: JavaTrình điều khiển tập lệnh

Bước 2) Enter the following program into the shell:

var myMessage='Hello World';
printjson(myMessage);

Xin chào thế giới MongoDB: JavaTrình điều khiển tập lệnh

Code Giải thích:

  1. Chúng tôi chỉ đang tuyên bố một cách đơn giản JavaScript variable to store a string called ‘Hello World’.
  2. Chúng tôi đang sử dụng phương thức printjson để in biến ra màn hình.

đặt Python Người lái xe

Bước 1) Đảm bảo Python is installed on the system.

Bước 2) Install the mongo related drivers by issuing the below command:

pip install pymongo

Cài đặt trình điều khiển Ruby

Bước 1) Ensure Ruby is installed on the system.

Bước 2) Ensure gems is updated by issuing the command:

gem update --system

Bước 3) Install the mongo related drivers by issuing the below command:

gem install mongo

đặt MongoDB Compass – MongoDB Công cụ quản lý

Có những công cụ trên thị trường có sẵn để quản lý MongoDB. Một công cụ phi thương mại như vậy là MongoDB Compass. Some of the features of Compass are given below:

  1. Full power of the Mongo shell
  2. Nhiều vỏ
  3. Nhiều kết quả

Bước 1) Tới liên kết này và nhấp vào tải xuống.

đặt MongoDB Compass

Bước 2) Enter details in the popup and click submit.

đặt MongoDB Compass

Bước 3) Double click on the downloaded file.

đặt MongoDB Compass

Bước 4) Installation will auto-start.

đặt MongoDB Compass

Bước 5) Compass will launch with a Welcome screen.

đặt MongoDB Compass

Bước 6) Keep the privacy settings as default and click “Start Using Compass”.

đặt MongoDB Compass

Bước 7) You will see the home screen with a list of current databases.

đặt MongoDB Compass

MongoDB Cấu hình, nhập và xuất

Trước khi bắt đầu MongoDB máy chủ, khía cạnh quan trọng đầu tiên là định cấu hình thư mục dữ liệu nơi tất cả MongoDB data will be stored. This can be done in the following way:

MongoDB Cấu hình, nhập và xuất

Lệnh trên 'md \data\db' tạo một thư mục có tên \data\db ở vị trí hiện tại của bạn. MongoDB sẽ tự động tạo cơ sở dữ liệu ở vị trí này, vì đây là vị trí mặc định cho MongoDB để lưu trữ thông tin của nó. Chúng tôi chỉ đảm bảo thư mục có mặt, để MongoDB có thể tìm thấy nó khi nó bắt đầu.

Việc nhập dữ liệu vào MongoDB được thực hiện bằng lệnh “mongoimport”. Ví dụ sau đây cho thấy cách thực hiện điều này.

Bước 1) Create a CSV file called data.csv and put the following data in it:

Employeeid,EmployeeName
1,Guru99
2,Mohan
3,Smith

So in the above example, we are assuming we want to import 3 documents into a collection called data. The first row is called the header line, which will become the field names of the collection.

Bước 2) Issue the mongoimport command.

MongoDB Cấu hình, nhập và xuất

Code Giải thích:

  1. We are specifying the db option to say which database the data should be imported to.
  2. The type option is to specify that we are importing a csv file.
  3. Remember that the first row is called the header line, which will become the field names of the collection; that is why we specify the –headerline option. And then we specify our data.csv file.

Đầu ra

MongoDB Cấu hình, nhập và xuất

Kết quả đầu ra ghi rõ 3 tài liệu đã được import vào MongoDB.

Xuất khẩu MongoDB is done by using the mongoexport command.

MongoDB Cấu hình, nhập và xuất

Code Giải thích:

  1. Chúng tôi đang chỉ định tùy chọn db để cho biết dữ liệu sẽ được xuất từ ​​cơ sở dữ liệu nào.
  2. We are specifying the collection option to say which collection to use.
  3. The third option is to specify that we want to export to a csv file.
  4. Thứ tư là chỉ định trường nào của bộ sưu tập sẽ được xuất.
  5. Tùy chọn –out chỉ định tên của tệp csv để xuất dữ liệu sang.

Đầu ra

MongoDB Cấu hình, nhập và xuất

Kết quả đầu ra cho thấy rõ ràng rằng 3 bản ghi đã được xuất từ MongoDB.

Cấu hình MongoDB máy chủ với tập tin cấu hình

One can configure the mongod server instance to start up with a configuration file. The configuration file contains settings that are equivalent to the mongod command-line options. For example, suppose you wanted MongoDB to store all its logging information to a custom location, then follow the below steps:

Bước 1) Create a file called “mongod.conf” and store the below information in the file.

Cấu hình MongoDB Máy chủ có tệp cấu hình

  1. The first line of the file specifies that we want to add configuration for the system log file, that is where the information about what the server is doing goes, in a custom log file.
  2. Tùy chọn thứ hai là đề cập rằng vị trí sẽ là một tệp.
  3. This mentions the location of the log file.
  4. logAppend: “true” có nghĩa là đảm bảo rằng thông tin nhật ký tiếp tục được thêm vào tệp nhật ký. Nếu bạn đặt giá trị là “false”, thì tệp sẽ bị xóa và được tạo mới bất cứ khi nào máy chủ khởi động lại.

Bước 2) Start the mongod server process and specify the above created configuration file as a parameter. The screenshot of how this can be done is shown below.

Cấu hình MongoDB Máy chủ có tệp cấu hình

Once the above command is executed, the server process will start using this configuration file, and if you go to the /etc directory on your system, you will see the mongod.log file created. The below snapshot shows an example of what a log file would look like.

Cấu hình MongoDB Máy chủ có tệp cấu hình

Làm thế nào để cài đặt MongoDB trên nền tảng đám mây (AWS, Google, Azure)

You do not need to install the MongoDB server and configure it. You can deploy a MongoDB Máy chủ Atlas trên đám mây trên các nền tảng như AWS, Google Cloudvà Azure, and connect to the instance using a client. Below are the detailed steps:

Bước 1) Tới liên kết này.

  1. Nhập thông tin cá nhân
  2. Đồng ý với các điều khoản
  3. Click the button “Get Started Free”

đặt MongoDB trên đám mây

Bước 2) Click “Build my first cluster”.

đặt MongoDB trên đám mây

Bước 3) Bạn có thể chọn giữa AWS, Google Cloudvà Azure as your cloud provider. In this tutorial, we will use AWS, which is set by default. Make no other changes on the page and click “Create Cluster".

đặt MongoDB trên đám mây

Bước 4) Cluster creation takes some time.

đặt MongoDB trên đám mây

Bước 5) After some time you will see the cluster ready.

đặt MongoDB trên đám mây

Bước 6) Click Security > Add new user.

đặt MongoDB trên đám mây

Bước 7) Trên màn hình tiếp theo:

  1. Nhập thông tin xác thực của người dùng
  2. Gán đặc quyền
  3. Nhấp vào nút Thêm người dùng

đặt MongoDB trên đám mây

Bước 8) In the dashboard, click the connect button.

  1. Danh sách trắng kết nối IP của bạn
  2. Chọn phương thức kết nối

đặt MongoDB trên đám mây

Bước 9) Select the connection method of your choice to connect to the MongoDB máy chủ.

đặt MongoDB trên đám mây

Câu Hỏi Thường Gặp

Yes. AI assistants can generate mongod configuration files, explain connection errors, and suggest fixes for driver or service issues. You should still verify commands against the official MongoDB documentation before applying them.

Vâng. MongoDB Atlas includes Atlas Vector Search and AI integrations that let you build semantic search and retrieval-augmented generation apps. It stores embeddings alongside documents, removing the need for a separate vector database.

Vâng. MongoDB Community Server is free and open source for Windows, macOSvà Linux. MongoDB Atlas also provides a free cloud tier, while Enterprise Edition adds paid advanced features and support.

Community Server is installed and managed on your own machine or server. Atlas is a fully managed cloud service that handles setup, scaling, backups, and security on AWS, Google Cloud, hoặc là Azure.

Tóm tắt bài viết này với: