Tài liệu về nhà → Hướng dẫn sử dụng MongoDB → MongoDB Manual
{ "_id" : 1, "location" : "24th Street", "in_stock" : [ "apples", "oranges", "bananas" ] } { "_id" : 2, "location" : "36th Street", "in_stock" : [ "bananas", "pears", "grapes" ] } { "_id" : 3, "location" : "82nd Street", "in_stock" : [ "cantaloupes", "watermelons", "apples" ] }
0return một boolean cho biết liệu một giá trị được chỉ định có ở trong một mảng hay không.Returns a boolean indicating whether a specified value is in an array.
Ghi chú
Tài liệu này mô tả toán tử tổng hợp
{ "_id" : 1, "location" : "24th Street", "in_stock" : [ "apples", "oranges", "bananas" ] } { "_id" : 2, "location" : "36th Street", "in_stock" : [ "bananas", "pears", "grapes" ] } { "_id" : 3, "location" : "82nd Street", "in_stock" : [ "cantaloupes", "watermelons", "apples" ] }
0. Đối với toán tử truy vấn { "_id" : 1, "location" : "24th Street", "in_stock" : [ "apples", "oranges", "bananas" ] } { "_id" : 2, "location" : "36th Street", "in_stock" : [ "bananas", "pears", "grapes" ] } { "_id" : 3, "location" : "82nd Street", "in_stock" : [ "cantaloupes", "watermelons", "apples" ] }
0, xem $ in.{ "_id" : 1, "location" : "24th Street", "in_stock" : [ "apples", "oranges", "bananas" ] } { "_id" : 2, "location" : "36th Street", "in_stock" : [ "bananas", "pears", "grapes" ] } { "_id" : 3, "location" : "82nd Street", "in_stock" : [ "cantaloupes", "watermelons", "apples" ] }
0 aggregation operator. For the { "_id" : 1, "location" : "24th Street", "in_stock" : [ "apples", "oranges", "bananas" ] } { "_id" : 2, "location" : "36th Street", "in_stock" : [ "bananas", "pears", "grapes" ] } { "_id" : 3, "location" : "82nd Street", "in_stock" : [ "cantaloupes", "watermelons", "apples" ] }
0 query operator, see $in.
0 có cú pháp biểu thức toán tử sau: has the following operator expression syntax:{ "_id" : 1, "location" : "24th Street", "in_stock" : [ "apples", "oranges", "bananas" ] } { "_id" : 2, "location" : "36th Street", "in_stock" : [ "bananas", "pears", "grapes" ] } { "_id" : 3, "location" : "82nd Street", "in_stock" : [ "cantaloupes", "watermelons", "apples" ] }
{ $in: [ , ] }
| Bất kỳ biểu thức hợp lệ. | ||||||
| Bất kỳ biểu thức hợp lệ nào giải quyết thành một mảng. |
Không giống như toán tử truy vấn
{ "_id" : 1, "location" : "24th Street", "in_stock" : [ "apples", "oranges", "bananas" ] } { "_id" : 2, "location" : "36th Street", "in_stock" : [ "bananas", "pears", "grapes" ] } { "_id" : 3, "location" : "82nd Street", "in_stock" : [ "cantaloupes", "watermelons", "apples" ] }
0, toán tử tổng hợp { "_id" : 1, "location" : "24th Street", "in_stock" : [ "apples", "oranges", "bananas" ] } { "_id" : 2, "location" : "36th Street", "in_stock" : [ "bananas", "pears", "grapes" ] } { "_id" : 3, "location" : "82nd Street", "in_stock" : [ "cantaloupes", "watermelons", "apples" ] }
0 không hỗ trợ khớp với các biểu thức thông thường.{ "_id" : 1, "location" : "24th Street", "in_stock" : [ "apples", "oranges", "bananas" ] } { "_id" : 2, "location" : "36th Street", "in_stock" : [ "bananas", "pears", "grapes" ] } { "_id" : 3, "location" : "82nd Street", "in_stock" : [ "cantaloupes", "watermelons", "apples" ] }
0 operator does not support matching by
regular expressions.
|
| ||||||||||||||||||||
|
| ||||||||||||||||||||
|
| ||||||||||||||||||||
|
| ||||||||||||||||||||
|
| ||||||||||||||||||||
|
| ||||||||||||||||||||
|
|
0 Không có lỗi trong một trong các trường hợp sau: nếu biểu thức $ trong không được đưa ra chính xác hai đối số hoặc nếu đối số thứ hai không giải quyết được cho một mảng. fails with an error in either of the following cases: if the $in expression is not given exactly two arguments, or if the second argument does not resolve to an array.{ "_id" : 1, "location" : "24th Street", "in_stock" : [ "apples", "oranges", "bananas" ] } { "_id" : 2, "location" : "36th Street", "in_stock" : [ "bananas", "pears", "grapes" ] } { "_id" : 3, "location" : "82nd Street", "in_stock" : [ "cantaloupes", "watermelons", "apples" ] }
Một bộ sưu tập có tên
{ "_id" : 1, "store location" : "24th Street", "has bananas" : true } { "_id" : 2, "store location" : "36th Street", "has bananas" : true } { "_id" : 3, "store location" : "82nd Street", "has bananas" : false }
3 có các tài liệu sau:{ "_id" : 1, "location" : "24th Street", "in_stock" : [ "apples", "oranges", "bananas" ] } { "_id" : 2, "location" : "36th Street", "in_stock" : [ "bananas", "pears", "grapes" ] } { "_id" : 3, "location" : "82nd Street", "in_stock" : [ "cantaloupes", "watermelons", "apples" ] }
Hoạt động tổng hợp sau đây xem xét mảng
{ "_id" : 1, "store location" : "24th Street", "has bananas" : true } { "_id" : 2, "store location" : "36th Street", "has bananas" : true } { "_id" : 3, "store location" : "82nd Street", "has bananas" : false }
4 trong mỗi tài liệu và xác định xem chuỗi { "_id" : 1, "store location" : "24th Street", "has bananas" : true } { "_id" : 2, "store location" : "36th Street", "has bananas" : true } { "_id" : 3, "store location" : "82nd Street", "has bananas" : false }
5 có mặt hay không.db.fruit.aggregate[[ { $project: { "store location" : "$location", "has bananas" : { $in: [ "bananas", "$in_stock" ] } } } ]]
Hoạt động trả về các kết quả sau:
{ "_id" : 1, "store location" : "24th Street", "has bananas" : true } { "_id" : 2, "store location" : "36th Street", "has bananas" : true } { "_id" : 3, "store location" : "82nd Street", "has bananas" : false }
Tài liệu về nhà → Hướng dẫn sử dụng MongoDB → MongoDB Manual
{ "_id" : 1, "store location" : "24th Street", "has bananas" : true } { "_id" : 2, "store location" : "36th Street", "has bananas" : true } { "_id" : 3, "store location" : "82nd Street", "has bananas" : false }
6Filters Các tài liệu chỉ truyền các tài liệu phù hợp với [các] điều kiện được chỉ định cho giai đoạn đường ống tiếp theo.Filters the documents to pass only the documents that match the specified condition[s] to the next pipeline stage.
Giai đoạn
{ "_id" : 1, "store location" : "24th Street", "has bananas" : true } { "_id" : 2, "store location" : "36th Street", "has bananas" : true } { "_id" : 3, "store location" : "82nd Street", "has bananas" : false }
6 có dạng nguyên mẫu sau:{ "_id" : 1, "store location" : "24th Street", "has bananas" : true } { "_id" : 2, "store location" : "36th Street", "has bananas" : true } { "_id" : 3, "store location" : "82nd Street", "has bananas" : false }
6 stage has the following prototype form:{ $match: { $expr: { } } }
6 lấy một tài liệu chỉ định các điều kiện truy vấn. Cú pháp truy vấn giống hệt với cú pháp truy vấn hoạt động đọc; tức là { "_id" : 1, "store location" : "24th Street", "has bananas" : true } { "_id" : 2, "store location" : "36th Street", "has bananas" : true } { "_id" : 3, "store location" : "82nd Street", "has bananas" : false }
6 không chấp nhận các biểu thức tổng hợp thô. Thay vào đó, hãy sử dụng biểu thức truy vấn { "_id" : 1, "store location" : "24th Street", "has bananas" : true } { "_id" : 2, "store location" : "36th Street", "has bananas" : true } { "_id" : 3, "store location" : "82nd Street", "has bananas" : false }
0 để bao gồm biểu thức tập hợp trong
6 takes a document that
specifies the query conditions. The query syntax is identical to the read operation query syntax; i.e. { "_id" : 1, "store location" : "24th Street", "has bananas" : true } { "_id" : 2, "store location" : "36th Street", "has bananas" : true } { "_id" : 3, "store location" : "82nd Street", "has bananas" : false }
6 does not accept
raw aggregation expressions. Instead, use a { "_id" : 1, "store location" : "24th Street", "has bananas" : true } { "_id" : 2, "store location" : "36th Street", "has bananas" : true } { "_id" : 3, "store location" : "82nd Street", "has bananas" : false }
{ $match: { $expr: { } } }
0 query expression to include aggregation expression in
{ "_id" : 1, "store location" : "24th Street", "has bananas" : true } { "_id" : 2, "store location" : "36th Street", "has bananas" : true } { "_id" : 3, "store location" : "82nd Street", "has bananas" : false }
6Đặt
6 càng sớm trong đường ống tổng hợp càng tốt. Bởi vì{ "_id" : 1, "store location" : "24th Street", "has bananas" : true } { "_id" : 2, "store location" : "36th Street", "has bananas" : true } { "_id" : 3, "store location" : "82nd Street", "has bananas" : false }
6 giới hạn tổng số tài liệu trong đường ống tổng hợp, trước đó, các hoạt động{ "_id" : 1, "store location" : "24th Street", "has bananas" : true } { "_id" : 2, "store location" : "36th Street", "has bananas" : true } { "_id" : 3, "store location" : "82nd Street", "has bananas" : false }
6 giảm thiểu số lượng xử lý xuống đường ống.{ "_id" : 1, "store location" : "24th Street", "has bananas" : true } { "_id" : 2, "store location" : "36th Street", "has bananas" : true } { "_id" : 3, "store location" : "82nd Street", "has bananas" : false }
6 as early in the aggregation pipeline as possible. Because{ "_id" : 1, "store location" : "24th Street", "has bananas" : true } { "_id" : 2, "store location" : "36th Street", "has bananas" : true } { "_id" : 3, "store location" : "82nd Street", "has bananas" : false }
6 limits the total number of documents in the aggregation pipeline, earlier{ "_id" : 1, "store location" : "24th Street", "has bananas" : true } { "_id" : 2, "store location" : "36th Street", "has bananas" : true } { "_id" : 3, "store location" : "82nd Street", "has bananas" : false }
6 operations minimize the amount of processing down the pipe.{ "_id" : 1, "store location" : "24th Street", "has bananas" : true } { "_id" : 2, "store location" : "36th Street", "has bananas" : true } { "_id" : 3, "store location" : "82nd Street", "has bananas" : false } Nếu bạn đặt
6 vào đầu đường ống, truy vấn có thể tận dụng các chỉ mục như bất kỳ{ "_id" : 1, "store location" : "24th Street", "has bananas" : true } { "_id" : 2, "store location" : "36th Street", "has bananas" : true } { "_id" : 3, "store location" : "82nd Street", "has bananas" : false }
6 hoặc{ $match: { $expr: { } } }
7 nào khác{ $match: { $expr: { } } }
6 at the very beginning of a pipeline, the query can take advantage of indexes like any other{ "_id" : 1, "store location" : "24th Street", "has bananas" : true } { "_id" : 2, "store location" : "36th Street", "has bananas" : true } { "_id" : 3, "store location" : "82nd Street", "has bananas" : false }
6 or{ $match: { $expr: { } } }
7{ $match: { $expr: { } } }
Cú pháp truy vấn
6 giống hệt với cú pháp truy vấn hoạt động đọc; tức là{ "_id" : 1, "store location" : "24th Street", "has bananas" : true } { "_id" : 2, "store location" : "36th Street", "has bananas" : true } { "_id" : 3, "store location" : "82nd Street", "has bananas" : false }
6 không chấp nhận các biểu thức tổng hợp thô. Để bao gồm biểu thức tập hợp trong{ "_id" : 1, "store location" : "24th Street", "has bananas" : true } { "_id" : 2, "store location" : "36th Street", "has bananas" : true } { "_id" : 3, "store location" : "82nd Street", "has bananas" : false }
6, hãy sử dụng biểu thức truy vấn{ "_id" : 1, "store location" : "24th Street", "has bananas" : true } { "_id" : 2, "store location" : "36th Street", "has bananas" : true } { "_id" : 3, "store location" : "82nd Street", "has bananas" : false }
0:{ $match: { $expr: { } } }
6 query syntax is identical to the read operation query syntax; i.e.{ "_id" : 1, "store location" : "24th Street", "has bananas" : true } { "_id" : 2, "store location" : "36th Street", "has bananas" : true } { "_id" : 3, "store location" : "82nd Street", "has bananas" : false }
6 does not accept raw aggregation expressions. To include aggregation expression in{ "_id" : 1, "store location" : "24th Street", "has bananas" : true } { "_id" : 2, "store location" : "36th Street", "has bananas" : true } { "_id" : 3, "store location" : "82nd Street", "has bananas" : false }
6, use a{ "_id" : 1, "store location" : "24th Street", "has bananas" : true } { "_id" : 2, "store location" : "36th Street", "has bananas" : true } { "_id" : 3, "store location" : "82nd Street", "has bananas" : false }
0 query expression:{ $match: { $expr: { } } }
{ $match: { $expr: { } } }
Bạn không thể sử dụng
2 trong các truy vấn{ "_id" : ObjectId["512bc95fe835e68f199c8686"], "author" : "dave", "score" : 80, "views" : 100 } { "_id" : ObjectId["512bc962e835e68f199c8687"], "author" : "dave", "score" : 85, "views" : 521 } { "_id" : ObjectId["55f5a192d4bede9ac365b257"], "author" : "ahn", "score" : 60, "views" : 1000 } { "_id" : ObjectId["55f5a192d4bede9ac365b258"], "author" : "li", "score" : 55, "views" : 5000 } { "_id" : ObjectId["55f5a1d3d4bede9ac365b259"], "author" : "annT", "score" : 60, "views" : 50 } { "_id" : ObjectId["55f5a1d3d4bede9ac365b25a"], "author" : "li", "score" : 94, "views" : 999 } { "_id" : ObjectId["55f5a1d3d4bede9ac365b25b"], "author" : "ty", "score" : 95, "views" : 1000 }
6 như một phần của đường ống tổng hợp.{ "_id" : 1, "store location" : "24th Street", "has bananas" : true } { "_id" : 2, "store location" : "36th Street", "has bananas" : true } { "_id" : 3, "store location" : "82nd Street", "has bananas" : false }
6 queries as part of the aggregation pipeline.{ "_id" : 1, "store location" : "24th Street", "has bananas" : true } { "_id" : 2, "store location" : "36th Street", "has bananas" : true } { "_id" : 3, "store location" : "82nd Street", "has bananas" : false } Bạn không thể sử dụng
4 hoặc{ "_id" : ObjectId["512bc95fe835e68f199c8686"], "author" : "dave", "score" : 80, "views" : 100 } { "_id" : ObjectId["512bc962e835e68f199c8687"], "author" : "dave", "score" : 85, "views" : 521 } { "_id" : ObjectId["55f5a192d4bede9ac365b257"], "author" : "ahn", "score" : 60, "views" : 1000 } { "_id" : ObjectId["55f5a192d4bede9ac365b258"], "author" : "li", "score" : 55, "views" : 5000 } { "_id" : ObjectId["55f5a1d3d4bede9ac365b259"], "author" : "annT", "score" : 60, "views" : 50 } { "_id" : ObjectId["55f5a1d3d4bede9ac365b25a"], "author" : "li", "score" : 94, "views" : 999 } { "_id" : ObjectId["55f5a1d3d4bede9ac365b25b"], "author" : "ty", "score" : 95, "views" : 1000 }
5 trong các truy vấn{ "_id" : ObjectId["512bc95fe835e68f199c8686"], "author" : "dave", "score" : 80, "views" : 100 } { "_id" : ObjectId["512bc962e835e68f199c8687"], "author" : "dave", "score" : 85, "views" : 521 } { "_id" : ObjectId["55f5a192d4bede9ac365b257"], "author" : "ahn", "score" : 60, "views" : 1000 } { "_id" : ObjectId["55f5a192d4bede9ac365b258"], "author" : "li", "score" : 55, "views" : 5000 } { "_id" : ObjectId["55f5a1d3d4bede9ac365b259"], "author" : "annT", "score" : 60, "views" : 50 } { "_id" : ObjectId["55f5a1d3d4bede9ac365b25a"], "author" : "li", "score" : 94, "views" : 999 } { "_id" : ObjectId["55f5a1d3d4bede9ac365b25b"], "author" : "ty", "score" : 95, "views" : 1000 }
6 như một phần của đường ống tổng hợp. Thay vào đó, bạn có thể:{ "_id" : 1, "store location" : "24th Street", "has bananas" : true } { "_id" : 2, "store location" : "36th Street", "has bananas" : true } { "_id" : 3, "store location" : "82nd Street", "has bananas" : false }
6 queries as part of the aggregation pipeline. As an alternative, you can either:{ "_id" : 1, "store location" : "24th Street", "has bananas" : true } { "_id" : 2, "store location" : "36th Street", "has bananas" : true } { "_id" : 3, "store location" : "82nd Street", "has bananas" : false } Sử dụng giai đoạn
7 thay vì giai đoạn{ "_id" : ObjectId["512bc95fe835e68f199c8686"], "author" : "dave", "score" : 80, "views" : 100 } { "_id" : ObjectId["512bc962e835e68f199c8687"], "author" : "dave", "score" : 85, "views" : 521 } { "_id" : ObjectId["55f5a192d4bede9ac365b257"], "author" : "ahn", "score" : 60, "views" : 1000 } { "_id" : ObjectId["55f5a192d4bede9ac365b258"], "author" : "li", "score" : 55, "views" : 5000 } { "_id" : ObjectId["55f5a1d3d4bede9ac365b259"], "author" : "annT", "score" : 60, "views" : 50 } { "_id" : ObjectId["55f5a1d3d4bede9ac365b25a"], "author" : "li", "score" : 94, "views" : 999 } { "_id" : ObjectId["55f5a1d3d4bede9ac365b25b"], "author" : "ty", "score" : 95, "views" : 1000 }
6.{ "_id" : 1, "store location" : "24th Street", "has bananas" : true } { "_id" : 2, "store location" : "36th Street", "has bananas" : true } { "_id" : 3, "store location" : "82nd Street", "has bananas" : false }
6 stage.{ "_id" : 1, "store location" : "24th Street", "has bananas" : true } { "_id" : 2, "store location" : "36th Street", "has bananas" : true } { "_id" : 3, "store location" : "82nd Street", "has bananas" : false } Sử dụng toán tử truy vấn
9 với{ "_id" : ObjectId["512bc95fe835e68f199c8686"], "author" : "dave", "score" : 80, "views" : 100 } { "_id" : ObjectId["512bc962e835e68f199c8687"], "author" : "dave", "score" : 85, "views" : 521 } { "_id" : ObjectId["55f5a192d4bede9ac365b257"], "author" : "ahn", "score" : 60, "views" : 1000 } { "_id" : ObjectId["55f5a192d4bede9ac365b258"], "author" : "li", "score" : 55, "views" : 5000 } { "_id" : ObjectId["55f5a1d3d4bede9ac365b259"], "author" : "annT", "score" : 60, "views" : 50 } { "_id" : ObjectId["55f5a1d3d4bede9ac365b25a"], "author" : "li", "score" : 94, "views" : 999 } { "_id" : ObjectId["55f5a1d3d4bede9ac365b25b"], "author" : "ty", "score" : 95, "views" : 1000 }
0 hoặcdb.articles.aggregate[ [ { $match : { author : "dave" } } ] ];
1 trong giai đoạndb.articles.aggregate[ [ { $match : { author : "dave" } } ] ];
6.{ "_id" : 1, "store location" : "24th Street", "has bananas" : true } { "_id" : 2, "store location" : "36th Street", "has bananas" : true } { "_id" : 3, "store location" : "82nd Street", "has bananas" : false }
6 stage.{ "_id" : 1, "store location" : "24th Street", "has bananas" : true } { "_id" : 2, "store location" : "36th Street", "has bananas" : true } { "_id" : 3, "store location" : "82nd Street", "has bananas" : false }
Để sử dụng
3 trong giai đoạndb.articles.aggregate[ [ { $match : { author : "dave" } } ] ];
6, giai đoạn{ "_id" : 1, "store location" : "24th Street", "has bananas" : true } { "_id" : 2, "store location" : "36th Street", "has bananas" : true } { "_id" : 3, "store location" : "82nd Street", "has bananas" : false }
6 phải là giai đoạn đầu tiên của đường ống.{ "_id" : 1, "store location" : "24th Street", "has bananas" : true } { "_id" : 2, "store location" : "36th Street", "has bananas" : true } { "_id" : 3, "store location" : "82nd Street", "has bananas" : false }
6 stage, the{ "_id" : 1, "store location" : "24th Street", "has bananas" : true } { "_id" : 2, "store location" : "36th Street", "has bananas" : true } { "_id" : 3, "store location" : "82nd Street", "has bananas" : false }
6 stage has to be the first stage of the pipeline.{ "_id" : 1, "store location" : "24th Street", "has bananas" : true } { "_id" : 2, "store location" : "36th Street", "has bananas" : true } { "_id" : 3, "store location" : "82nd Street", "has bananas" : false } Lượt xem không hỗ trợ tìm kiếm văn bản.
Các ví dụ sử dụng một bộ sưu tập có tên
db.articles.aggregate[ [ { $match : { author : "dave" } } ] ];
6 với các tài liệu sau:{ "_id" : ObjectId["512bc95fe835e68f199c8686"], "author" : "dave", "score" : 80, "views" : 100 } { "_id" : ObjectId["512bc962e835e68f199c8687"], "author" : "dave", "score" : 85, "views" : 521 } { "_id" : ObjectId["55f5a192d4bede9ac365b257"], "author" : "ahn", "score" : 60, "views" : 1000 } { "_id" : ObjectId["55f5a192d4bede9ac365b258"], "author" : "li", "score" : 55, "views" : 5000 } { "_id" : ObjectId["55f5a1d3d4bede9ac365b259"], "author" : "annT", "score" : 60, "views" : 50 } { "_id" : ObjectId["55f5a1d3d4bede9ac365b25a"], "author" : "li", "score" : 94, "views" : 999 } { "_id" : ObjectId["55f5a1d3d4bede9ac365b25b"], "author" : "ty", "score" : 95, "views" : 1000 }
Hoạt động sau sử dụng
{ "_id" : 1, "store location" : "24th Street", "has bananas" : true } { "_id" : 2, "store location" : "36th Street", "has bananas" : true } { "_id" : 3, "store location" : "82nd Street", "has bananas" : false }
6 để thực hiện phù hợp với bình đẳng đơn giản:{ "_id" : 1, "store location" : "24th Street", "has bananas" : true } { "_id" : 2, "store location" : "36th Street", "has bananas" : true } { "_id" : 3, "store location" : "82nd Street", "has bananas" : false }
6 to perform a simple equality
match:db.articles.aggregate[ [ { $match : { author : "dave" } } ] ];
{ "_id" : 1, "store location" : "24th Street", "has bananas" : true } { "_id" : 2, "store location" : "36th Street", "has bananas" : true } { "_id" : 3, "store location" : "82nd Street", "has bananas" : false }
6 chọn các tài liệu trong đó trường db.articles.aggregate[ [ { $match : { author : "dave" } } ] ];
9 bằng { "_id" : ObjectId["512bc95fe835e68f199c8686"], "author" : "dave", "score" : 80, "views" : 100 } { "_id" : ObjectId["512bc962e835e68f199c8687"], "author" : "dave", "score" : 85, "views" : 521 }
0 và tổng hợp trả về như sau:{ "_id" : 1, "store location" : "24th Street", "has bananas" : true } { "_id" : 2, "store location" : "36th Street", "has bananas" : true } { "_id" : 3, "store location" : "82nd Street", "has bananas" : false }
6 selects the documents where the db.articles.aggregate[ [ { $match : { author : "dave" } } ] ];
9 field equals { "_id" : ObjectId["512bc95fe835e68f199c8686"], "author" : "dave", "score" : 80, "views" : 100 } { "_id" : ObjectId["512bc962e835e68f199c8687"], "author" : "dave", "score" : 85, "views" : 521 }
0, and the aggregation returns the following:{ "_id" : ObjectId["512bc95fe835e68f199c8686"], "author" : "dave", "score" : 80, "views" : 100 } { "_id" : ObjectId["512bc962e835e68f199c8687"], "author" : "dave", "score" : 85, "views" : 521 }
Ví dụ sau đây chọn các tài liệu để xử lý bằng toán tử đường ống
{ "_id" : 1, "store location" : "24th Street", "has bananas" : true } { "_id" : 2, "store location" : "36th Street", "has bananas" : true } { "_id" : 3, "store location" : "82nd Street", "has bananas" : false }
6 và sau đó đưa kết quả vào toán tử đường ống { "_id" : ObjectId["512bc95fe835e68f199c8686"], "author" : "dave", "score" : 80, "views" : 100 } { "_id" : ObjectId["512bc962e835e68f199c8687"], "author" : "dave", "score" : 85, "views" : 521 }
2 để tính toán số lượng tài liệu:{ "_id" : 1, "store location" : "24th Street", "has bananas" : true } { "_id" : 2, "store location" : "36th Street", "has bananas" : true } { "_id" : 3, "store location" : "82nd Street", "has bananas" : false }
6 pipeline operator and then pipes the results to the { "_id" : ObjectId["512bc95fe835e68f199c8686"], "author" : "dave", "score" : 80, "views" : 100 } { "_id" : ObjectId["512bc962e835e68f199c8687"], "author" : "dave", "score" : 85, "views" : 521 }
2 pipeline operator to compute a count of the documents:db.articles.aggregate[ [ { $match: { $or: [ { score: { $gt: 70, $lt: 90 } }, { views: { $gte: 1000 } } ] } }, { $group: { _id: null, count: { $sum: 1 } } } ] ];
Trong đường ống tổng hợp,
{ "_id" : 1, "store location" : "24th Street", "has bananas" : true } { "_id" : 2, "store location" : "36th Street", "has bananas" : true } { "_id" : 3, "store location" : "82nd Street", "has bananas" : false }
6 chọn các tài liệu trong đó { "_id" : ObjectId["512bc95fe835e68f199c8686"], "author" : "dave", "score" : 80, "views" : 100 } { "_id" : ObjectId["512bc962e835e68f199c8687"], "author" : "dave", "score" : 85, "views" : 521 }
4 lớn hơn { "_id" : ObjectId["512bc95fe835e68f199c8686"], "author" : "dave", "score" : 80, "views" : 100 } { "_id" : ObjectId["512bc962e835e68f199c8687"], "author" : "dave", "score" : 85, "views" : 521 }
5 và nhỏ hơn { "_id" : ObjectId["512bc95fe835e68f199c8686"], "author" : "dave", "score" : 80, "views" : 100 } { "_id" : ObjectId["512bc962e835e68f199c8687"], "author" : "dave", "score" : 85, "views" : 521 }
6 hoặc { "_id" : ObjectId["512bc95fe835e68f199c8686"], "author" : "dave", "score" : 80, "views" : 100 } { "_id" : ObjectId["512bc962e835e68f199c8687"], "author" : "dave", "score" : 85, "views" : 521 }
7 lớn hơn hoặc bằng { "_id" : ObjectId["512bc95fe835e68f199c8686"], "author" : "dave", "score" : 80, "views" : 100 } { "_id" : ObjectId["512bc962e835e68f199c8687"], "author" : "dave", "score" : 85, "views" : 521 }
8. Các tài liệu này sau đó được đưa đến { "_id" : ObjectId["512bc95fe835e68f199c8686"], "author" : "dave", "score" : 80, "views" : 100 } { "_id" : ObjectId["512bc962e835e68f199c8687"], "author" : "dave", "score" : 85, "views" : 521 }
2 để thực hiện đếm. Tổng hợp trả về những điều sau:{ "_id" : 1, "store location" : "24th Street", "has bananas" : true } { "_id" : 2, "store location" : "36th Street", "has bananas" : true } { "_id" : 3, "store location" : "82nd Street", "has bananas" : false }
6 selects the documents where either the { "_id" : ObjectId["512bc95fe835e68f199c8686"], "author" : "dave", "score" : 80, "views" : 100 } { "_id" : ObjectId["512bc962e835e68f199c8687"], "author" : "dave", "score" : 85, "views" : 521 }
4 is greater than { "_id" : ObjectId["512bc95fe835e68f199c8686"], "author" : "dave", "score" : 80, "views" : 100 } { "_id" : ObjectId["512bc962e835e68f199c8687"], "author" : "dave", "score" : 85, "views" : 521 }
5 and less than { "_id" : ObjectId["512bc95fe835e68f199c8686"], "author" : "dave", "score" : 80, "views" : 100 } { "_id" : ObjectId["512bc962e835e68f199c8687"], "author" : "dave", "score" : 85, "views" : 521 }
6 or the { "_id" : ObjectId["512bc95fe835e68f199c8686"], "author" : "dave", "score" : 80, "views" : 100 } { "_id" : ObjectId["512bc962e835e68f199c8687"], "author" : "dave", "score" : 85, "views" : 521 }
7 is greater than or equal to { "_id" : ObjectId["512bc95fe835e68f199c8686"], "author" : "dave", "score" : 80, "views" : 100 } { "_id" : ObjectId["512bc962e835e68f199c8687"], "author" : "dave", "score" : 85, "views" : 521 }
8. These documents are then piped to the { "_id" : ObjectId["512bc95fe835e68f199c8686"], "author" : "dave", "score" : 80, "views" : 100 } { "_id" : ObjectId["512bc962e835e68f199c8687"], "author" : "dave", "score" : 85, "views" : 521 }
2 to perform a
count. The aggregation returns the following:{ "_id" : null, "count" : 5 }
Tham khảo các trang sau để biết thêm thông tin và sử dụng các trường hợp về tổng hợp.
Đối với các truy vấn
db.articles.aggregate[ [ { $match: { $or: [ { score: { $gt: 70, $lt: 90 } }, { views: { $gte: 1000 } } ] } }, { $group: { _id: null, count: { $sum: 1 } } } ] ];
0 của bạn đối với dữ liệu trên cụm Atlas của bạn, bạn có thể sử dụng tùy chọn Toán tử Atlas SearchCompound db.articles.aggregate[ [ { $match: { $or: [ { score: { $gt: 70, $lt: 90 } }, { views: { $gte: 1000 } } ] } }, { $group: { _id: null, count: { $sum: 1 } } } ] ];
1 để khớp hoặc lọc tài liệu. Chạy { "_id" : 1, "store location" : "24th Street", "has bananas" : true } { "_id" : 2, "store location" : "36th Street", "has bananas" : true } { "_id" : 3, "store location" : "82nd Street", "has bananas" : false }
6 sau db.articles.aggregate[ [ { $match: { $or: [ { score: { $gt: 70, $lt: 90 } }, { views: { $gte: 1000 } } ] } }, { $group: { _id: null, count: { $sum: 1 } } } ] ];
0 ít hoạt động hơn so với chạy db.articles.aggregate[ [ { $match: { $or: [ { score: { $gt: 70, $lt: 90 } }, { views: { $gte: 1000 } } ] } }, { $group: { _id: null, count: { $sum: 1 } } } ] ];
0 với tùy chọn toán tử tổng hợp db.articles.aggregate[ [ { $match: { $or: [ { score: { $gt: 70, $lt: 90 } }, { views: { $gte: 1000 } } ] } }, { $group: { _id: null, count: { $sum: 1 } } } ] ];
1. Để tìm hiểu thêm về tùy chọn db.articles.aggregate[ [ { $match: { $or: [ { score: { $gt: 70, $lt: 90 } }, { views: { $gte: 1000 } } ] } }, { $group: { _id: null, count: { $sum: 1 } } } ] ];
1, xem Hợp chất.db.articles.aggregate[ [ { $match: { $or: [ { score: { $gt: 70, $lt: 90 } }, { views: { $gte: 1000 } } ] } }, { $group: { _id: null, count: { $sum: 1 } } } ] ];
0 queries against data on your
Atlas cluster, you can use the Atlas Search compound operator db.articles.aggregate[ [ { $match: { $or: [ { score: { $gt: 70, $lt: 90 } }, { views: { $gte: 1000 } } ] } }, { $group: { _id: null, count: { $sum: 1 } } } ] ];
1 option to match or filter documents. Running
{ "_id" : 1, "store location" : "24th Street", "has bananas" : true } { "_id" : 2, "store location" : "36th Street", "has bananas" : true } { "_id" : 3, "store location" : "82nd Street", "has bananas" : false }
6 after db.articles.aggregate[ [ { $match: { $or: [ { score: { $gt: 70, $lt: 90 } }, { views: { $gte: 1000 } } ] } }, { $group: { _id: null, count: { $sum: 1 } } } ] ];
0 is less performant than running
db.articles.aggregate[ [ { $match: { $or: [ { score: { $gt: 70, $lt: 90 } }, { views: { $gte: 1000 } } ] } }, { $group: { _id: null, count: { $sum: 1 } } } ] ];
0 with the compound operator db.articles.aggregate[ [ { $match: { $or: [ { score: { $gt: 70, $lt: 90 } }, { views: { $gte: 1000 } } ] } }, { $group: { _id: null, count: { $sum: 1 } } } ] ];
1 option. To learn more about the db.articles.aggregate[ [ { $match: { $or: [ { score: { $gt: 70, $lt: 90 } }, { views: { $gte: 1000 } } ] } }, { $group: { _id: null, count: { $sum: 1 } } } ] ];
1 option, see compound.Tập hợp với tập dữ liệu mã zip
Tập hợp với dữ liệu ưu tiên người dùng