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.

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.
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.
Bước 3) Chấp nhận Thỏa thuận cấp phép người dùng cuối
- Chấp nhận Thỏa thuận cấp phép người dùng cuối.
- Bấm tiếp.
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.
Bước 5) Cấu hình dịch vụ
- Select “Run service as Network Service user”. Make a note of the data directory; we will need this later.
- Bấm tiếp.
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.
Step 7) Click Next once completed
Installation begins. Click Next once completed.
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.
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.
Bước 2) Enter the following program into the shell:
var myMessage='Hello World'; printjson(myMessage);
Code Giải thích:
- 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’.
- 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:
- Full power of the Mongo shell
- Nhiều vỏ
- 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.
Bước 2) Enter details in the popup and click submit.
Bước 3) Double click on the downloaded file.
Bước 4) Installation will auto-start.
Bước 5) Compass will launch with a Welcome screen.
Bước 6) Keep the privacy settings as default and click “Start Using Compass”.
Bước 7) You will see the home screen with a list of current databases.
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:
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.
Code Giải thích:
- We are specifying the db option to say which database the data should be imported to.
- The type option is to specify that we are importing a csv file.
- 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
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.
Code Giải thích:
- 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.
- We are specifying the collection option to say which collection to use.
- The third option is to specify that we want to export to a csv file.
- Thứ tư là chỉ định trường nào của bộ sưu tập sẽ được xuất.
- Tùy chọn –out chỉ định tên của tệp csv để xuất dữ liệu sang.
Đầu ra
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.
- 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.
- Tùy chọn thứ hai là đề cập rằng vị trí sẽ là một tệp.
- This mentions the location of the log file.
- 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.
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.
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.
- Nhập thông tin cá nhân
- Đồng ý với các điều khoản
- Click the button “Get Started Free”
Bước 2) Click “Build my first cluster”.
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".
Bước 4) Cluster creation takes some time.
Bước 5) After some time you will see the cluster ready.
Bước 6) Click Security > Add new user.
Bước 7) Trên màn hình tiếp theo:
- Nhập thông tin xác thực của người dùng
- Gán đặc quyền
- Nhấp vào nút Thêm người dùng
Bước 8) In the dashboard, click the connect button.
- Danh sách trắng kết nối IP của bạn
- Chọn phương thức kết nối
Bước 9) Select the connection method of your choice to connect to the MongoDB máy chủ.


































