Chúng ta có thể tạo nhiều bộ sưu tập trong mongodb không?
Những gì bạn đang hỏi là một câu hỏi rộng không có câu trả lời đúng duy nhất. Đây là một câu hỏi thiết kế hơn là bất kỳ vấn đề MongoDB cụ thể nào Show MongoDB hoàn toàn có khả năng thực hiện những gì bạn yêu cầu trong kịch bản của mình (20 nghìn * 10 bộ sưu tập = 200 nghìn bộ sưu tập trong một db hoặc 20 nghìn db với 10 bộ sưu tập mỗi bộ, tùy thuộc vào giới hạn tệp mở của HĐH cơ bản). Tuy nhiên, không nên đẩy bất kỳ công nghệ nào đến những con số cực đoan như vậy mà không suy nghĩ cẩn thận do vấn đề về bảo mật, tính khả dụng và hiệu suất Trang MongoDB Limits and Thresholds mô tả chi tiết các giới hạn của khả năng MongoDB Tuy nhiên, có nhiều câu hỏi quan trọng hơn để bạn xem xét tùy thuộc vào trường hợp sử dụng của bạn, ví dụ:
Đó chỉ là một số câu hỏi cơ bản trong đầu tôi. Tôi chắc chắn rằng có nhiều hơn nữa mà bạn có thể nghĩ về Mongoose là thư viện Mô hình hóa dữ liệu đối tượng (ODM) cho MongoDB. Nó định nghĩa một lược đồ được gõ mạnh, với các giá trị mặc định và xác thực lược đồ mà sau này được ánh xạ tới tài liệu MongoDB Để tạo bộ sưu tập với Mongoose, bạn phải tạo hai thứ cần thiết.
Cài đặt Mongoose Bước 1. Bạn có thể truy cập vào link Install cầy mangut để cài module cầy mangut. Bạn có thể cài đặt gói này bằng cách sử dụng lệnh này npm install mongoose
Bước 2. Bây giờ bạn có thể nhập mô-đun cầy mangut vào tệp của mình bằng cách sử dụng const mongoose = require('mongoose'); Thực hiện Bước 1. Tạo một thư mục và thêm mô hình. js và chính. js vào đó
Bước 2. Viết đoạn mã sau vào mô hình. tập tin js người mẫu. jsconst mongoose = require('mongoose');11 const mongoose = require('mongoose');12 const mongoose = require('mongoose');13 const mongoose = require('mongoose');14 const mongoose = require('mongoose');15 const mongoose = require('mongoose');16 const mongoose = require('mongoose');0 const mongoose = require('mongoose');1 const mongoose = require('mongoose');2 const mongoose = require('mongoose');3____14 const mongoose = require('mongoose');3____16 const mongoose = require('mongoose');3____18 const mongoose = require('mongoose');9 const mongoose = require('mongoose');15 const mongoose = require('mongoose');21 const mongoose = require('mongoose');22 const mongoose = require('mongoose');1 const mongoose = require('mongoose');2 const mongoose = require('mongoose');3____16 const mongoose = require('mongoose');3____128 const mongoose = require('mongoose');3____210 const mongoose = require('mongoose');9 const mongoose = require('mongoose');15 const mongoose = require('mongoose');13 const mongoose = require('mongoose');14 const mongoose = require('mongoose');1 const mongoose = require('mongoose');2 const mongoose = require('mongoose');3____16 const mongoose = require('mongoose');3____1110 const mongoose = require('mongoose');3____210 const mongoose = require('mongoose');113 const mongoose = require('mongoose');15 const mongoose = require('mongoose');115 const mongoose = require('mongoose');116 const mongoose = require('mongoose');117____1118 const mongoose = require('mongoose');119 const mongoose = require('mongoose');120 const mongoose = require('mongoose');121 const mongoose = require('mongoose');122 const mongoose = require('mongoose');123 const mongoose = require('mongoose');124 const mongoose = require('mongoose');15 const mongoose = require('mongoose');126 const mongoose = require('mongoose');127 const mongoose = require('mongoose');3____1129 const mongoose = require('mongoose');130 Bước 3. Kết nối cơ sở dữ liệu có thể dễ dàng được thiết lập bằng cầy mangut như const mongoose = require('mongoose');2 Nếu cơ sở dữ liệu GFG đã có sẵn thì kết nối sẽ được thiết lập nếu không thì cơ sở dữ liệu đầu tiên sẽ được tạo và kết nối sẽ được thiết lập Ở đây ban đầu chúng ta có một cơ sở dữ liệu trống GFG như trong hình bên dưới Cơ sở dữ liệu ban đầu trống Tạo đối tượng dữ liệu, bạn muốn chèn, cho cả bộ sưu tập rồi chèn như hình chính. tập tin js. Ngay sau khi chúng tôi chèn dữ liệu, bộ sưu tập của chúng tôi sẽ tự động được tạo Bước 4. Viết đoạn mã sau vào main. tập tin js chính. jsconst mongoose = require('mongoose');12 const mongoose = require('mongoose');13 const mongoose = require('mongoose');14 ________ 1134 ________ 1135 ________ 114 const mongoose = require('mongoose');15 const mongoose = require('mongoose');138 const mongoose = require('mongoose');139 const mongoose = require('mongoose');140 const mongoose = require('mongoose');141 const mongoose = require('mongoose');3____1143 const mongoose = require('mongoose');144 const mongoose = require('mongoose');145 const mongoose = require('mongoose');146 const mongoose = require('mongoose');141 const mongoose = require('mongoose');144 const mongoose = require('mongoose');149 const mongoose = require('mongoose');146 const mongoose = require('mongoose');141 const mongoose = require('mongoose');144 const mongoose = require('mongoose');153____1154 const mongoose = require('mongoose');3____19 const mongoose = require('mongoose');15 const mongoose = require('mongoose');158 const mongoose = require('mongoose');159 const mongoose = require('mongoose');3____1161 const mongoose = require('mongoose');3____1163 const mongoose = require('mongoose');164 const mongoose = require('mongoose');141 const mongoose = require('mongoose');3____1167 const mongoose = require('mongoose');168 const mongoose = require('mongoose');169 const mongoose = require('mongoose');143 const mongoose = require('mongoose');3____102 const mongoose = require('mongoose');3____1163 const mongoose = require('mongoose');05 const mongoose = require('mongoose');141 const mongoose = require('mongoose');3____1167 const mongoose = require('mongoose');09 const mongoose = require('mongoose');10 const mongoose = require('mongoose');15 const mongoose = require('mongoose');12 const mongoose = require('mongoose');13 const mongoose = require('mongoose');3____1163 const mongoose = require('mongoose');16 const mongoose = require('mongoose');141 const mongoose = require('mongoose');3____119 const mongoose = require('mongoose');3____121 const mongoose = require('mongoose');10 const mongoose = require('mongoose');15 const mongoose = require('mongoose');24 const mongoose = require('mongoose');25 const mongoose = require('mongoose');3____1163 const mongoose = require('mongoose');28 const mongoose = require('mongoose');141 const mongoose = require('mongoose');3____131 const mongoose = require('mongoose');3____121 const mongoose = require('mongoose');169 const mongoose = require('mongoose');143 const mongoose = require('mongoose');3____1163 const mongoose = require('mongoose');38 const mongoose = require('mongoose');141 const mongoose = require('mongoose');3____141 const mongoose = require('mongoose');3____143 const mongoose = require('mongoose');10 const mongoose = require('mongoose');15 const mongoose = require('mongoose');46 const mongoose = require('mongoose');47 const mongoose = require('mongoose');3____149 const mongoose = require('mongoose');144 const mongoose = require('mongoose');51____152 const mongoose = require('mongoose');14 const mongoose = require('mongoose');3____1113 const mongoose = require('mongoose');3____157____158 const mongoose = require('mongoose');59 const mongoose = require('mongoose');144 const mongoose = require('mongoose');61 const mongoose = require('mongoose');3____1113 const mongoose = require('mongoose');15 const mongoose = require('mongoose');65 const mongoose = require('mongoose');66 const mongoose = require('mongoose');3____149 const mongoose = require('mongoose');144 const mongoose = require('mongoose');51____152 const mongoose = require('mongoose');14 const mongoose = require('mongoose');3____1113 const mongoose = require('mongoose');3____157____158 const mongoose = require('mongoose');59 const mongoose = require('mongoose');144 const mongoose = require('mongoose');61 const mongoose = require('mongoose');3____1113 const mongoose = require('mongoose');15 const mongoose = require('mongoose');84 const mongoose = require('mongoose');85 const mongoose = require('mongoose');3____149 const mongoose = require('mongoose');144 const mongoose = require('mongoose');51____152 const mongoose = require('mongoose');14 const mongoose = require('mongoose');3____1113 const mongoose = require('mongoose');3____157____158 const mongoose = require('mongoose');59 const mongoose = require('mongoose');144 const mongoose = require('mongoose');61 const mongoose = require('mongoose');3____1113 Bước 5. Chạy chính. js bằng lệnh bên dưới const mongoose = require('mongoose');1 đầu ra. Chúng ta có thể thấy trong bảng điều khiển rằng tất cả dữ liệu đã được lưu thành công Đầu ra sau khi thực hiện chính. js cơ sở dữ liệu. Bây giờ chúng ta có thể thấy rằng ba bộ sưu tập các khóa học, sinh viên, giáo viên được tạo trong cơ sở dữ liệu GFG của chúng tôi Bạn có thể tạo bao nhiêu bộ sưu tập trong MongoDB?Nói chung, chúng tôi khuyên bạn nên giới hạn bộ sưu tập ở mức 10.000 mỗi bộ bản sao . Khi người dùng bắt đầu vượt quá 10.000 bộ sưu tập, họ thường thấy hiệu suất giảm xuống. Để tránh kiểu mẫu này, hãy kiểm tra cơ sở dữ liệu của bạn và xóa các bộ sưu tập không cần thiết.
Chúng tôi có thể tạo bộ sưu tập phụ trong MongoDB không?Trong MongoDB, bạn không thể sử dụng giới hạn cho bộ sưu tập phụ . Tuy nhiên, sử dụng giới hạn trên tổng thể tài liệu. Để hiển thị một số giá trị cụ thể từ một mảng, hãy ưu tiên $slice.
Kích thước tối đa của bộ sưu tập trong MongoDB là bao nhiêu?Ghi chú
Kích thước trung bình của các giá trị khóa phân đoạn 512 byte 256 byte Số lần chia tối đa 32,768 65,536 Kích thước bộ sưu tập tối đa (Kích thước khối 64 MB) 1TB 2TB Kích thước bộ sưu tập tối đa (Kích thước khối 128 MB) 2TB 4 TB Kích thước bộ sưu tập tối đa (Kích thước khối 256 MB) 4 TB 8 TB Các bộ sưu tập được tạo trong MongoDB như thế nào?Trong MongoDB, bạn không cần tạo bộ sưu tập. MongoDB tự động tạo bộ sưu tập khi bạn chèn một số tài liệu . |