Tài liệu về nhà → Hướng dẫn sử dụng MongoDB → MongoDB Manual
db.inventory.insertOne[{ "_id" : 1, "item" : "ABC1", sizes: [ "S", "M", "L"] }]
4Deconstructs Một trường mảng từ các tài liệu đầu vào để xuất một tài liệu cho từng phần tử. Mỗi tài liệu đầu ra là tài liệu đầu vào với giá trị của trường mảng được thay thế bằng phần tử.Deconstructs an array field from the input documents to output a document for each element. Each output document is the input document with the value of the array field replaced by the element.
Bạn có thể vượt qua toán hạng đường dẫn trường hoặc toán hạng tài liệu để thư giãn trường mảng.
Bạn có thể chuyển đường dẫn trường mảng đến
db.inventory.insertOne[{ "_id" : 1, "item" : "ABC1", sizes: [ "S", "M", "L"] }]
4. Khi sử dụng cú pháp này, db.inventory.insertOne[{ "_id" : 1, "item" : "ABC1", sizes: [ "S", "M", "L"] }]
4 không xuất tài liệu nếu giá trị trường là null, thiếu hoặc một mảng trống.db.inventory.insertOne[{ "_id" : 1, "item" : "ABC1", sizes: [ "S", "M", "L"] }]
4. When using this syntax, db.inventory.insertOne[{ "_id" : 1, "item" : "ABC1", sizes: [ "S", "M", "L"] }]
4 does not output a document if the field value is null, missing, or an empty array.{ $unwind: }
Khi bạn chỉ định đường dẫn trường, tiền tố tên trường có dấu hiệu đô la
db.inventory.insertOne[{ "_id" : 1, "item" : "ABC1", sizes: [ "S", "M", "L"] }]
7 và gửi kèm theo trích dẫn.Bạn có thể chuyển một tài liệu cho
db.inventory.insertOne[{ "_id" : 1, "item" : "ABC1", sizes: [ "S", "M", "L"] }]
4 để chỉ định các tùy chọn hành vi khác nhau.db.inventory.insertOne[{ "_id" : 1, "item" : "ABC1", sizes: [ "S", "M", "L"] }]
4 to specify various behavior options.{ $unwind: { path: , includeArrayIndex: , preserveNullAndEmptyArrays: } }
đường dẫn | sợi dây | Đường dẫn trường đến một trường mảng. Để chỉ định đường dẫn trường, tiền tố tên trường có dấu hiệu đô la 7 và đặt trong các trích dẫn.
|
bao gồm cả hai | sợi dây | Đường dẫn trường đến một trường mảng. Để chỉ định đường dẫn trường, tiền tố tên trường có dấu hiệu đô la 7 và đặt trong các trích dẫn.
|
bao gồm cả hai | boolean | Optional.
Nếu 1, nếu 2 là null, thiếu hoặc một mảng trống, 4 sẽ xuất ra tài liệu.
|
Nếu
4, nếudb.inventory.aggregate[ [ { $unwind : "$sizes" } ] ]
2 là null, thiếu hoặc một mảng trống,db.inventory.aggregate[ [ { $unwind : "$sizes" } ] ]
4 không xuất ra một tài liệu.db.inventory.insertOne[{ "_id" : 1, "item" : "ABC1", sizes: [ "S", "M", "L"] }]
Giá trị mặc định là
4.preserveNullAndEmptyArrays option.db.inventory.aggregate[ [ { $unwind : "$sizes" } ] ]
Khi toán hạng không giải quyết được một mảng, nhưng không bị thiếu,
db.inventory.aggregate[ [ { $unwind : "$sizes" } ] ]
8 hoặc một mảng trống, db.inventory.insertOne[{ "_id" : 1, "item" : "ABC1", sizes: [ "S", "M", "L"] }]
4 coi toán hạng là một mảng phần tử duy nhất.db.inventory.insertOne[{ "_id" : 1, "item" : "ABC1", sizes: [ "S", "M", "L"] }]
4, by
default, ignores the input document and will not output documents for that input document.Khi toán hạng là
db.inventory.aggregate[ [ { $unwind : "$sizes" } ] ]
8, bị thiếu hoặc một mảng trống db.inventory.insertOne[{ "_id" : 1, "item" : "ABC1", sizes: [ "S", "M", "L"] }]
4 tuân theo hành vi được đặt cho tùy chọn PreservenAllandEmptyArrays.preserveNullAndEmptyArrays option.Nếu bạn chỉ định một đường dẫn cho một trường không tồn tại trong tài liệu đầu vào hoặc trường là một mảng trống,
db.inventory.insertOne[{ "_id" : 1, "item" : "ABC1", sizes: [ "S", "M", "L"] }]
4, theo mặc định, bỏ qua tài liệu đầu vào và sẽ không xuất tài liệu cho tài liệu đầu vào đó.{ "_id" : 1, "item" : "ABC1", "sizes" : "S" } { "_id" : 1, "item" : "ABC1", "sizes" : "M" } { "_id" : 1, "item" : "ABC1", "sizes" : "L" }
3, create a sample collection named { "_id" : 1, "item" : "ABC1", "sizes" : "S" } { "_id" : 1, "item" : "ABC1", "sizes" : "M" } { "_id" : 1, "item" : "ABC1", "sizes" : "L" }
4 with the following document:db.inventory.insertOne[{ "_id" : 1, "item" : "ABC1", sizes: [ "S", "M", "L"] }]
Để xuất các tài liệu nơi trường mảng bị thiếu, null hoặc một mảng trống, hãy sử dụng tùy chọn PreservenAllandEmptyArrays. db.inventory.insertOne[{ "_id" : 1, "item" : "ABC1", sizes: [ "S", "M", "L"] }]
4 stage to output a document for each element in the
{ "_id" : 1, "item" : "ABC1", "sizes" : "S" } { "_id" : 1, "item" : "ABC1", "sizes" : "M" } { "_id" : 1, "item" : "ABC1", "sizes" : "L" }
6
array:db.inventory.aggregate[ [ { $unwind : "$sizes" } ] ]
Trong
{ "_id" : 1, "item" : "ABC1", "sizes" : "S" } { "_id" : 1, "item" : "ABC1", "sizes" : "M" } { "_id" : 1, "item" : "ABC1", "sizes" : "L" }
3, hãy tạo một bộ sưu tập mẫu có tên { "_id" : 1, "item" : "ABC1", "sizes" : "S" } { "_id" : 1, "item" : "ABC1", "sizes" : "M" } { "_id" : 1, "item" : "ABC1", "sizes" : "L" }
4 với tài liệu sau:{ "_id" : 1, "item" : "ABC1", "sizes" : "S" } { "_id" : 1, "item" : "ABC1", "sizes" : "M" } { "_id" : 1, "item" : "ABC1", "sizes" : "L" }
Tập hợp sau đây sử dụng giai đoạn
db.inventory.insertOne[{ "_id" : 1, "item" : "ABC1", sizes: [ "S", "M", "L"] }]
4 để xuất tài liệu cho từng phần tử trong mảng { "_id" : 1, "item" : "ABC1", "sizes" : "S" } { "_id" : 1, "item" : "ABC1", "sizes" : "M" } { "_id" : 1, "item" : "ABC1", "sizes" : "L" }
6:Hoạt động trả về các kết quả sau:
db.clothing.insertMany[[ { "_id" : 1, "item" : "Shirt", "sizes": [ "S", "M", "L"] }, { "_id" : 2, "item" : "Shorts", "sizes" : [ ] }, { "_id" : 3, "item" : "Hat", "sizes": "M" }, { "_id" : 4, "item" : "Gloves" }, { "_id" : 5, "item" : "Scarf", "sizes" : null } ]]
Mỗi tài liệu giống hệt với tài liệu đầu vào ngoại trừ giá trị của trường
6 hiện có giá trị từ mảng { "_id" : 1, "item" : "ABC1", "sizes" : "S" } { "_id" : 1, "item" : "ABC1", "sizes" : "M" } { "_id" : 1, "item" : "ABC1", "sizes" : "L" }
6 gốc. treats the
{ "_id" : 1, "item" : "ABC1", "sizes" : "S" } { "_id" : 1, "item" : "ABC1", "sizes" : "M" } { "_id" : 1, "item" : "ABC1", "sizes" : "L" }
{ "_id" : 1, "item" : "ABC1", "sizes" : "S" } { "_id" : 1, "item" : "ABC1", "sizes" : "M" } { "_id" : 1, "item" : "ABC1", "sizes" : "L" }
6 field as a single element array if:Xem xét bộ sưu tập
9:{ "_id" : 1, "item" : "ABC1", "sizes" : "S" } { "_id" : 1, "item" : "ABC1", "sizes" : "M" } { "_id" : 1, "item" : "ABC1", "sizes" : "L" }
4 coi trườngdb.inventory.insertOne[{ "_id" : 1, "item" : "ABC1", sizes: [ "S", "M", "L"] }]
6 là một mảng phần tử duy nhất nếu:{ "_id" : 1, "item" : "ABC1", "sizes" : "S" } { "_id" : 1, "item" : "ABC1", "sizes" : "M" } { "_id" : 1, "item" : "ABC1", "sizes" : "L" } lĩnh vực này có mặt,
giá trị không phải là null, và db.inventory.insertOne[{ "_id" : 1, "item" : "ABC1", sizes: [ "S", "M", "L"] }]
4
db.clothing.aggregate[ [ { $unwind: { path: "$sizes" } } ] ]
Giá trị không phải là một mảng trống. db.inventory.insertOne[{ "_id" : 1, "item" : "ABC1", sizes: [ "S", "M", "L"] }]
4 operation returns:
{ _id: 1, item: 'Shirt', sizes: 'S' }, { _id: 1, item: 'Shirt', sizes: 'M' }, { _id: 1, item: 'Shirt', sizes: 'L' }, { _id: 3, item: 'Hat', sizes: 'M' }
Mở rộng các mảng
6 với{ "_id" : 1, "item" : "ABC1", "sizes" : "S" } { "_id" : 1, "item" : "ABC1", "sizes" : "M" } { "_id" : 1, "item" : "ABC1", "sizes" : "L" }
4db.inventory.insertOne[{ "_id" : 1, "item" : "ABC1", sizes: [ "S", "M", "L"] }]
4 returns a document for each element in thedb.inventory.insertOne[{ "_id" : 1, "item" : "ABC1", sizes: [ "S", "M", "L"] }]
6 field.{ "_id" : 1, "item" : "ABC1", "sizes" : "S" } { "_id" : 1, "item" : "ABC1", "sizes" : "M" } { "_id" : 1, "item" : "ABC1", "sizes" : "L" } Hoạt động
4 trả về:db.inventory.insertOne[{ "_id" : 1, "item" : "ABC1", sizes: [ "S", "M", "L"] }]
Trong tài liệu
5,db.clothing.insertMany[[ { "_id" : 1, "item" : "Shirt", "sizes": [ "S", "M", "L"] }, { "_id" : 2, "item" : "Shorts", "sizes" : [ ] }, { "_id" : 3, "item" : "Hat", "sizes": "M" }, { "_id" : 4, "item" : "Gloves" }, { "_id" : 5, "item" : "Scarf", "sizes" : null } ]]
6 là một mảng đông dân.{ "_id" : 1, "item" : "ABC1", "sizes" : "S" } { "_id" : 1, "item" : "ABC1", "sizes" : "M" } { "_id" : 1, "item" : "ABC1", "sizes" : "L" }
4 Trả về một tài liệu cho mỗi phần tử trong trườngdb.inventory.insertOne[{ "_id" : 1, "item" : "ABC1", sizes: [ "S", "M", "L"] }]
6.{ "_id" : 1, "item" : "ABC1", "sizes" : "S" } { "_id" : 1, "item" : "ABC1", "sizes" : "M" } { "_id" : 1, "item" : "ABC1", "sizes" : "L" }
Trong tài liệu db.clothing.insertMany[[ { "_id" : 1, "item" : "Shirt", "sizes": [ "S", "M", "L"] }, { "_id" : 2, "item" : "Shorts", "sizes" : [ ] }, { "_id" : 3, "item" : "Hat", "sizes": "M" }, { "_id" : 4, "item" : "Gloves" }, { "_id" : 5, "item" : "Scarf", "sizes" : null } ]]
9, { "_id" : 1, "item" : "ABC1", "sizes" : "S" } { "_id" : 1, "item" : "ABC1", "sizes" : "M" } { "_id" : 1, "item" : "ABC1", "sizes" : "L" }
6 giải quyết cho một mảng phần tử duy nhất.
db.clothing.insertMany[[ { "_id" : 1, "item" : "Shirt", "sizes": [ "S", "M", "L"] }, { "_id" : 2, "item" : "Shorts", "sizes" : [ ] }, { "_id" : 3, "item" : "Hat", "sizes": "M" }, { "_id" : 4, "item" : "Gloves" }, { "_id" : 5, "item" : "Scarf", "sizes" : null } ]]
{ "_id" : 1, "item" : "ABC1", "sizes" : "S" } { "_id" : 1, "item" : "ABC1", "sizes" : "M" } { "_id" : 1, "item" : "ABC1", "sizes" : "L" }
Tài liệu
db.clothing.aggregate[ [ { $unwind: { path: "$sizes" } } ] ]
1 và db.clothing.aggregate[ [ { $unwind: { path: "$sizes" } } ] ]
2 không trả lại bất cứ điều gì vì trường { "_id" : 1, "item" : "ABC1", "sizes" : "S" } { "_id" : 1, "item" : "ABC1", "sizes" : "M" } { "_id" : 1, "item" : "ABC1", "sizes" : "L" }
6 không thể được giảm xuống thành một mảng phần tử.db.inventory.insertOne[{ "_id" : 1, "item" : "ABC1", sizes: [ "S", "M", "L"] }]
4 operations are
equivalent.db.clothing.aggregate[ [ { $unwind: "$sizes" } ] ] db.clothing.aggregate[ [ { $unwind: { path: "$sizes" } } ] ]
Ghi chú db.clothing.aggregate[ [ { $unwind: { path: "$sizes" } } ] ] db.clothing.aggregate[ [ { $unwind: { path: "$sizes" } } ] ]
6 and
7 examples use the following collection:
db.inventory2.insertMany[[ { "_id" : 1, "item" : "ABC", price: NumberDecimal["80"], "sizes": [ "S", "M", "L"] }, { "_id" : 2, "item" : "EFG", price: NumberDecimal["120"], "sizes" : [ ] }, { "_id" : 3, "item" : "IJK", price: NumberDecimal["160"], "sizes": "M" }, { "_id" : 4, "item" : "LMN" , price: NumberDecimal["10"] }, { "_id" : 5, "item" : "XYZ", price: NumberDecimal["5.75"], "sizes" : null } ]]
Cú pháp
db.clothing.aggregate[ [ { $unwind: { path: "$sizes" } } ] ]
4 là tùy chọn. Các hoạt động db.inventory.insertOne[{ "_id" : 1, "item" : "ABC1", sizes: [ "S", "M", "L"] }]
4 sau đây là tương đương.db.inventory.insertOne[{ "_id" : 1, "item" : "ABC1", sizes: [ "S", "M", "L"] }]
4 operation uses the preserveNullAndEmptyArrays option to include documents whose { "_id" : 1, "item" : "ABC1", "sizes" : "S" } { "_id" : 1, "item" : "ABC1", "sizes" : "M" } { "_id" : 1, "item" : "ABC1", "sizes" : "L" }
6 field is null, missing, or an empty array.{ $unwind: { path: , includeArrayIndex: , preserveNullAndEmptyArrays: } }
0Các ví dụ
db.clothing.aggregate[ [ { $unwind: { path: "$sizes" } } ] ]
6 và db.clothing.aggregate[ [ { $unwind: { path: "$sizes" } } ] ]
7 Sử dụng bộ sưu tập sau:{ $unwind: { path: , includeArrayIndex: , preserveNullAndEmptyArrays: } }
1Hoạt động
db.inventory.insertOne[{ "_id" : 1, "item" : "ABC1", sizes: [ "S", "M", "L"] }]
4 sau đây sử dụng tùy chọn PreservenAllandEmptyArrays để bao gồm các tài liệu có trường { "_id" : 1, "item" : "ABC1", "sizes" : "S" } { "_id" : 1, "item" : "ABC1", "sizes" : "M" } { "_id" : 1, "item" : "ABC1", "sizes" : "L" }
6 là null, thiếu hoặc một mảng trống.db.inventory.insertOne[{ "_id" : 1, "item" : "ABC1", sizes: [ "S", "M", "L"] }]
4 operation uses the includeArrayIndex option to include the
array index in the output.{ $unwind: { path: , includeArrayIndex: , preserveNullAndEmptyArrays: } }
2Đầu ra bao gồm những tài liệu trong đó trường
{ "_id" : 1, "item" : "ABC1", "sizes" : "S" } { "_id" : 1, "item" : "ABC1", "sizes" : "M" } { "_id" : 1, "item" : "ABC1", "sizes" : "L" }
6 là null, thiếu hoặc một mảng trống:{ $unwind: { path: , includeArrayIndex: , preserveNullAndEmptyArrays: } }
3Hoạt động
db.inventory.insertOne[{ "_id" : 1, "item" : "ABC1", sizes: [ "S", "M", "L"] }]
4 sau đây sử dụng tùy chọn bao gồm inflay Index để bao gồm chỉ mục mảng vào đầu ra.{ "_id" : 1, "item" : "ABC1", "sizes" : "S" } { "_id" : 1, "item" : "ABC1", "sizes" : "M" } { "_id" : 1, "item" : "ABC1", "sizes" : "L" }
3, create a
sample collection named { _id: 1, item: 'Shirt', sizes: 'S' }, { _id: 1, item: 'Shirt', sizes: 'M' }, { _id: 1, item: 'Shirt', sizes: 'L' }, { _id: 3, item: 'Hat', sizes: 'M' }
8 with the following documents:{ $unwind: { path: , includeArrayIndex: , preserveNullAndEmptyArrays: } }
4Hoạt động thư giãn mảng
{ "_id" : 1, "item" : "ABC1", "sizes" : "S" } { "_id" : 1, "item" : "ABC1", "sizes" : "M" } { "_id" : 1, "item" : "ABC1", "sizes" : "L" }
6 và bao gồm chỉ mục mảng trong trường { _id: 1, item: 'Shirt', sizes: 'S' }, { _id: 1, item: 'Shirt', sizes: 'M' }, { _id: 1, item: 'Shirt', sizes: 'L' }, { _id: 3, item: 'Hat', sizes: 'M' }
3 mới. Nếu trường { "_id" : 1, "item" : "ABC1", "sizes" : "S" } { "_id" : 1, "item" : "ABC1", "sizes" : "M" } { "_id" : 1, "item" : "ABC1", "sizes" : "L" }
6 không giải quyết được cho một mảng đông dân nhưng không bị thiếu, null hoặc một mảng trống, trường { _id: 1, item: 'Shirt', sizes: 'S' }, { _id: 1, item: 'Shirt', sizes: 'M' }, { _id: 1, item: 'Shirt', sizes: 'L' }, { _id: 3, item: 'Hat', sizes: 'M' }
3 là db.inventory.aggregate[ [ { $unwind : "$sizes" } ] ]
8.{ $unwind: { path: , includeArrayIndex: , preserveNullAndEmptyArrays: } }
5Trong { "_id" : 1, "item" : "ABC1", "sizes" : "S" } { "_id" : 1, "item" : "ABC1", "sizes" : "M" } { "_id" : 1, "item" : "ABC1", "sizes" : "L" }
3, hãy tạo một bộ sưu tập mẫu có tên { _id: 1, item: 'Shirt', sizes: 'S' }, { _id: 1, item: 'Shirt', sizes: 'M' }, { _id: 1, item: 'Shirt', sizes: 'L' }, { _id: 3, item: 'Hat', sizes: 'M' }
8 với các tài liệu sau:Đường ống sau khi thư giãn mảng
{ "_id" : 1, "item" : "ABC1", "sizes" : "S" } { "_id" : 1, "item" : "ABC1", "sizes" : "M" } { "_id" : 1, "item" : "ABC1", "sizes" : "L" }
6 và nhóm các tài liệu kết quả bởi các giá trị kích thước không chắc chắn:db.inventory.insertOne[{ "_id" : 1, "item" : "ABC1", sizes: [ "S", "M", "L"] }]
4 stage outputs a new document for each element in the { "_id" : 1, "item" : "ABC1", "sizes" : "S" } { "_id" : 1, "item" : "ABC1", "sizes" : "M" } { "_id" : 1, "item" : "ABC1", "sizes" : "L" }
6 array. The stage uses
the preserveNullAndEmptyArrays option to include in the output those documents where { "_id" : 1, "item" : "ABC1", "sizes" : "S" } { "_id" : 1, "item" : "ABC1", "sizes" : "M" } { "_id" : 1, "item" : "ABC1", "sizes" : "L" }
6 field is missing, null or an empty array. This stage passes the following documents to the next stage:{ $unwind: { path: , includeArrayIndex: , preserveNullAndEmptyArrays: } }
1Giai đoạn đầu tiên:Giai đoạn
db.inventory.insertOne[{ "_id" : 1, "item" : "ABC1", sizes: [ "S", "M", "L"] }]
4 xuất ra một tài liệu mới cho mỗi phần tử trong mảng { "_id" : 1, "item" : "ABC1", "sizes" : "S" } { "_id" : 1, "item" : "ABC1", "sizes" : "M" } { "_id" : 1, "item" : "ABC1", "sizes" : "L" }
6. Giai đoạn sử dụng tùy chọn PreservenAllandEmptyArrays để đưa vào đầu ra các tài liệu đó trong đó trường { "_id" : 1, "item" : "ABC1", "sizes" : "S" } { "_id" : 1, "item" : "ABC1", "sizes" : "M" } { "_id" : 1, "item" : "ABC1", "sizes" : "L" }
6 bị thiếu, null hoặc một mảng trống. Giai đoạn này chuyển các tài liệu sau đây cho giai đoạn tiếp theo:{ $unwind: { path: , includeArrayIndex: , preserveNullAndEmptyArrays: } }
7Giai đoạn thứ hai:Giai đoạn
db.clothing.aggregate[ [ { $unwind: "$sizes" } ] ] db.clothing.aggregate[ [ { $unwind: { path: "$sizes" } } ] ]
3 nhóm các tài liệu bằng { "_id" : 1, "item" : "ABC1", "sizes" : "S" } { "_id" : 1, "item" : "ABC1", "sizes" : "M" } { "_id" : 1, "item" : "ABC1", "sizes" : "L" }
6 và tính toán giá trung bình của mỗi kích thước. Giai đoạn này chuyển các tài liệu sau đây cho giai đoạn tiếp theo:{ $unwind: { path: , includeArrayIndex: , preserveNullAndEmptyArrays: } }
8Mẹo
Trong
{ "_id" : 1, "item" : "ABC1", "sizes" : "S" } { "_id" : 1, "item" : "ABC1", "sizes" : "M" } { "_id" : 1, "item" : "ABC1", "sizes" : "L" }
3, hãy tạo một bộ sưu tập mẫu có tên db.clothing.aggregate[ [ { $unwind: "$sizes" } ] ] db.clothing.aggregate[ [ { $unwind: { path: "$sizes" } } ] ]
8 với các tài liệu sau:{ "_id" : 1, "item" : "ABC1", "sizes" : "S" } { "_id" : 1, "item" : "ABC1", "sizes" : "M" } { "_id" : 1, "item" : "ABC1", "sizes" : "L" }
3, create a sample collection named db.clothing.aggregate[ [ { $unwind: "$sizes" } ] ] db.clothing.aggregate[ [ { $unwind: { path: "$sizes" } } ] ]
8 with the following documents:{ $unwind: { path: , includeArrayIndex: , preserveNullAndEmptyArrays: } }
9Các nhóm hoạt động sau đây các mục được bán bởi thẻ của họ và tính toán tổng số tiền bán hàng cho mỗi thẻ.
db.inventory.insertOne[{ "_id" : 1, "item" : "ABC1", sizes: [ "S", "M", "L"] }]
0Giai đoạn đầu tiênGiai đoạn
db.inventory.insertOne[{ "_id" : 1, "item" : "ABC1", sizes: [ "S", "M", "L"] }]
4 đầu tiên xuất ra một tài liệu mới cho mỗi phần tử trong mảng db.inventory2.insertMany[[ { "_id" : 1, "item" : "ABC", price: NumberDecimal["80"], "sizes": [ "S", "M", "L"] }, { "_id" : 2, "item" : "EFG", price: NumberDecimal["120"], "sizes" : [ ] }, { "_id" : 3, "item" : "IJK", price: NumberDecimal["160"], "sizes": "M" }, { "_id" : 4, "item" : "LMN" , price: NumberDecimal["10"] }, { "_id" : 5, "item" : "XYZ", price: NumberDecimal["5.75"], "sizes" : null } ]]
0:db.inventory.insertOne[{ "_id" : 1, "item" : "ABC1", sizes: [ "S", "M", "L"] }]
4 stage outputs a new document for each element in the db.inventory2.insertMany[[ { "_id" : 1, "item" : "ABC", price: NumberDecimal["80"], "sizes": [ "S", "M", "L"] }, { "_id" : 2, "item" : "EFG", price: NumberDecimal["120"], "sizes" : [ ] }, { "_id" : 3, "item" : "IJK", price: NumberDecimal["160"], "sizes": "M" }, { "_id" : 4, "item" : "LMN" , price: NumberDecimal["10"] }, { "_id" : 5, "item" : "XYZ", price: NumberDecimal["5.75"], "sizes" : null } ]]
0 array:db.inventory.insertOne[{ "_id" : 1, "item" : "ABC1", sizes: [ "S", "M", "L"] }]
1Giai đoạn thứ haiGiai đoạn
db.inventory.insertOne[{ "_id" : 1, "item" : "ABC1", sizes: [ "S", "M", "L"] }]
4 thứ hai xuất ra một tài liệu mới cho mỗi phần tử trong mảng db.inventory2.insertMany[[ { "_id" : 1, "item" : "ABC", price: NumberDecimal["80"], "sizes": [ "S", "M", "L"] }, { "_id" : 2, "item" : "EFG", price: NumberDecimal["120"], "sizes" : [ ] }, { "_id" : 3, "item" : "IJK", price: NumberDecimal["160"], "sizes": "M" }, { "_id" : 4, "item" : "LMN" , price: NumberDecimal["10"] }, { "_id" : 5, "item" : "XYZ", price: NumberDecimal["5.75"], "sizes" : null } ]]
2:db.inventory.insertOne[{ "_id" : 1, "item" : "ABC1", sizes: [ "S", "M", "L"] }]
4 stage outputs a new document for each element in the db.inventory2.insertMany[[ { "_id" : 1, "item" : "ABC", price: NumberDecimal["80"], "sizes": [ "S", "M", "L"] }, { "_id" : 2, "item" : "EFG", price: NumberDecimal["120"], "sizes" : [ ] }, { "_id" : 3, "item" : "IJK", price: NumberDecimal["160"], "sizes": "M" }, { "_id" : 4, "item" : "LMN" , price: NumberDecimal["10"] }, { "_id" : 5, "item" : "XYZ", price: NumberDecimal["5.75"], "sizes" : null } ]]
2 arrays:db.inventory.insertOne[{ "_id" : 1, "item" : "ABC1", sizes: [ "S", "M", "L"] }]
2Giai đoạn thứ baGiai đoạn
db.clothing.aggregate[ [ { $unwind: "$sizes" } ] ] db.clothing.aggregate[ [ { $unwind: { path: "$sizes" } } ] ]
3 nhóm các tài liệu theo thẻ và tính toán tổng số lượng bán hàng với mỗi thẻ:db.inventory.insertOne[{ "_id" : 1, "item" : "ABC1", sizes: [ "S", "M", "L"] }]
3Mẹo
Tập hợp với bộ dữ liệu mã zip,
Tập hợp với dữ liệu ưu tiên người dùng