MongoDB Compass là một GUI mạnh mẽ để truy vấn, tổng hợp và phân tích dữ liệu MongoDB của bạn trong môi trường trực quan. La bàn miễn phí sử dụng và có sẵn nguồn và có thể chạy trên macOS, Windows và Linux Bạn có thể sử dụng MongoDB Compass để nhập và xuất dữ liệu đến và từ các bộ sưu tập. MongoDB Compass hỗ trợ nhập và xuất cho cả tệp JSON và CSV. Để nhập hoặc xuất dữ liệu vào hoặc từ một bộ sưu tập, hãy điều hướng đến chế độ xem bộ sưu tập chi tiết bằng cách chọn bộ sưu tập từ tab Cơ sở dữ liệu hoặc nhấp vào bộ sưu tập trong điều hướng bên trái Hầu hết các cơ sở dữ liệu và khung ngôn ngữ đều cho phép bạn xuất dữ liệu của mình. Điều này làm cho dữ liệu trở nên hữu ích ở nhiều dạng khác nhau bởi các chương trình, ứng dụng hoặc ngôn ngữ khác CSV, BSON và JSON là các định dạng tệp cơ sở dữ liệu phổ biến nhất Sử dụng công cụ mongoexport –db teams –collection PremierLeague LaLiga SerieA Ligue1 –out C:\Users\Random\teamsdata.json
5, MongoDB cho phép các nhà phát triển thực hiện điều này vì công cụ mongoexport –db teams –collection PremierLeague LaLiga SerieA Ligue1 –out C:\Users\Random\teamsdata.json
5 không hoạt động trong trình bao mongoexport –db teams –collection PremierLeague LaLiga SerieA Ligue1 –out C:\Users\Random\teamsdata.json
7; . Đây là một công cụ dòng lệnh hệ thốngHướng dẫn này sẽ nêu bật cách bạn có thể xuất tất cả các bộ sưu tập trong MongoDB sang CSV (Giá trị được phân tách bằng dấu phẩy) và các loại tệp JSON. Nhưng trước tiên chúng ta hãy tìm hiểu về công cụ mongoexport –db teams –collection PremierLeague LaLiga SerieA Ligue1 –out C:\Users\Random\teamsdata.json
5Bài viết này chứng minh như sau mongoexport –db teams –collection PremierLeague LaLiga SerieA Ligue1 –out C:\Users\Random\teamsdata.json
5 Công cụ CLI trong MongoDB- Cài đặt Công cụ CLI
mongoexport –db teams –collection PremierLeague LaLiga SerieA Ligue1 –out C:\Users\Random\teamsdata.json
5 - Xuất Bộ sưu tập sang JSON trong MongoDB
- Xuất Bộ sưu tập sang CSV trong MongoDB
Công cụ mongoexport –db teams –collection PremierLeague LaLiga SerieA Ligue1 –out C:\Users\Random\teamsdata.json
5 giúp xuất dữ liệu từ phiên bản MongoDB thành loại tệp JSON hoặc CSV. Kể từ MongoDB 4. Vào ngày 4 tháng 10, công cụ mongoexport –db teams –collection PremierLeague LaLiga SerieA Ligue1 –out C:\Users\Random\teamsdata.json
5 đã được cung cấp riêng biệt với Máy chủ MongoDBNó sử dụng phiên bản của nó. Công cụ mongoexport –db teams –collection PremierLeague LaLiga SerieA Ligue1 –out C:\Users\Random\teamsdata.json
5 CLI hỗ trợ các phiên bản MongoDB bên dưới- MongoDB 5. 0
- MongoDB 4. 4
- MongoDB 4. 2
- MongoDB 4. 0
Hãy bắt đầu thiết lập công cụ mongoexport –db teams –collection PremierLeague LaLiga SerieA Ligue1 –out C:\Users\Random\teamsdata.json
5. Gói mongoexport –db teams –collection PremierLeague LaLiga SerieA Ligue1 –out C:\Users\Random\teamsdata.json
3 bao gồm công cụ mongoexport –db teams –collection PremierLeague LaLiga SerieA Ligue1 –out C:\Users\Random\teamsdata.json
5Bạn sẽ làm theo các bước bên dưới để cài đặt mongoexport –db teams –collection PremierLeague LaLiga SerieA Ligue1 –out C:\Users\Random\teamsdata.json
5 từ trang web chính thức của MongoDBTruy cập trang tải xuống chính thức của MongoDBNhấp vào tab ________ 06 dưới tiêu đề ________ 07Kéo đàn accordion mongoexport –db teams –collection PremierLeague LaLiga SerieA Ligue1 –out C:\Users\Random\teamsdata.json
3 xuống bằng cách cuộn xuống và nhấp vào nóTrong biểu mẫu mongoexport –db teams –collection PremierLeague LaLiga SerieA Ligue1 –out C:\Users\Random\teamsdata.json
9, phiên bản mới nhất của gói công cụ cơ sở dữ liệu được chọn theo mặc định. Chọn nền tảng cho hệ thống của bạn và gói bạn yêu cầuCho phép quá trình cài đặt kết thúc trước khi sử dụng tiện ích mongoexport –db teams –collection PremierLeague LaLiga SerieA Ligue1 –out C:\Users\Random\teamsdata.json
5
Xuất Bộ sưu tập sang JSON trong MongoDBHãy bắt đầu bằng cách sử dụng công cụ mongoexport –db teams –collection PremierLeague LaLiga SerieA Ligue1 –out C:\Users\Random\teamsdata.json
5 để xuất tất cả các bộ sưu tập trong MongoDB. Sau đó, làm theo hướng dẫn bên dưới để xuất bộ sưu tập sang tệp JSONGiả sử chúng ta có một cơ sở dữ liệu tên là mongoexport –db teams –collection Ligue1 –type=csv –fields team,size,price –out C:\Users\Random\teamssdata.csv
2. Chúng tôi có một tập hợp các bộ sưu tập bên trong cơ sở dữ liệu này có tên là mongoexport –db teams –collection Ligue1 –type=csv –fields team,size,price –out C:\Users\Random\teamssdata.csv
3, mongoexport –db teams –collection Ligue1 –type=csv –fields team,size,price –out C:\Users\Random\teamssdata.csv
4, mongoexport –db teams –collection Ligue1 –type=csv –fields team,size,price –out C:\Users\Random\teamssdata.csv
5 và mongoexport –db teams –collection Ligue1 –type=csv –fields team,size,price –out C:\Users\Random\teamssdata.csv
6 mà chúng tôi muốn xuấtCũng giả sử bạn đã ghi lại một vài tài liệu trong đó. Bạn sẽ sử dụng những chi tiết này để chứng minh một ví dụ Cú pháp cho điều này được đưa ra dưới đây mongoexport –db teams –collection PremierLeague LaLiga SerieA Ligue1 –out C:\Users\Random\teamsdata.json
0- Cờ
mongoexport –db teams –collection Ligue1 –type=csv –fields team,size,price –out C:\Users\Random\teamssdata.csv
7 chúng tôi thêm ở đây là viết tắt của đường dẫn thư mục với tên tệp được đính kèm ở cuối - Bạn có thể chọn tạo một tệp có tên đó cho
mongoexport –db teams –collection PremierLeague LaLiga SerieA Ligue1 –out C:\Users\Random\teamsdata.json
5 tại điểm đến đó. Hoặc để nó cho mongoexport –db teams –collection PremierLeague LaLiga SerieA Ligue1 –out C:\Users\Random\teamsdata.json
5 tự tạo một cái ở đích đó với tên tệp đó
mongoexport –db teams –collection PremierLeague LaLiga SerieA Ligue1 –out C:\Users\Random\teamsdata.json
5 sẽ tự động tạo và thêm dữ liệu vào tệpHãy minh họa một ví dụ để bạn có thể dễ dàng làm theo các bước để xuất tất cả các bộ sưu tập trong MongoDB - Khởi động máy chủ MongoDB của bạn
- Bắt đầu bằng cách đi đến thiết bị đầu cuối hệ thống của bạn. Kiểm tra xem bạn có đang sử dụng shell
mongoexport –db teams –collection PremierLeague LaLiga SerieA Ligue1 –out C:\Users\Random\teamsdata.json
7 không - Để xuất tất cả các bộ sưu tập trong MongoDB ở định dạng JSON từ cơ sở dữ liệu, hãy chuyển lệnh này
mongoexport –db teams –collection PremierLeague LaLiga SerieA Ligue1 –out C:\Users\Random\teamsdata.json
Bây giờ bạn sẽ thấy một tệp JSON chứa dữ liệu được tạo ở đích Xuất Bộ sưu tập sang CSV trong MongoDBMicrosoft Excel thường xử lý tệp CSV. Bạn sẽ sử dụng cùng một cơ sở dữ liệu, mongoexport –db teams –collection Ligue1 –type=csv –fields team,size,price –out C:\Users\Random\teamssdata.csv
2Để xuất bộ sưu tập sang CSV trong MongoDB, hãy làm theo các bước được đề cập bên dưới Giờ đây, người dùng có thể xem tệp CSV với dữ liệu phù hợp được tạo tại vị trí được cung cấp |