Hướng dẫn gte and lte in mongodb aggregate - gte và lte trong mongodb tổng hợp

Tài liệu về nhà → Hướng dẫn sử dụng MongoDBMongoDB Manual

$lteComparing hai giá trị và trả về:

Compares two values and returns:

  • true khi giá trị đầu tiên nhỏ hơn hoặc tương đương với giá trị thứ hai.

  • { "_id" : 1, "item" : "abc1", description: "product 1", qty: 300 }
    { "_id" : 2, "item" : "abc2", description: "product 2", qty: 200 }
    { "_id" : 3, "item" : "xyz1", description: "product 3", qty: 250 }
    { "_id" : 4, "item" : "VWZ1", description: "product 4", qty: 300 }
    { "_id" : 5, "item" : "VWZ2", description: "product 5", qty: 180 }
    0 Khi giá trị thứ nhất lớn hơn giá trị thứ hai.

$lte so sánh cả giá trị và loại, sử dụng thứ tự so sánh BSON được chỉ định cho các giá trị của các loại khác nhau.$lte compares both value and type, using the specified BSON comparison order for values of different types.

$lte có cú pháp sau: has the following syntax:

{ $lte: [ , ] }

Để biết thêm thông tin về biểu thức, xem biểu thức.

Xem xét bộ sưu tập

{ "_id" : 1, "item" : "abc1", description: "product 1", qty: 300 }
{ "_id" : 2, "item" : "abc2", description: "product 2", qty: 200 }
{ "_id" : 3, "item" : "xyz1", description: "product 3", qty: 250 }
{ "_id" : 4, "item" : "VWZ1", description: "product 4", qty: 300 }
{ "_id" : 5, "item" : "VWZ2", description: "product 5", qty: 180 }
3 với các tài liệu sau:

{ "_id" : 1, "item" : "abc1", description: "product 1", qty: 300 }
{ "_id" : 2, "item" : "abc2", description: "product 2", qty: 200 }
{ "_id" : 3, "item" : "xyz1", description: "product 3", qty: 250 }
{ "_id" : 4, "item" : "VWZ1", description: "product 4", qty: 300 }
{ "_id" : 5, "item" : "VWZ2", description: "product 5", qty: 180 }

Hoạt động sau sử dụng toán tử $lte để xác định xem

{ "_id" : 1, "item" : "abc1", description: "product 1", qty: 300 }
{ "_id" : 2, "item" : "abc2", description: "product 2", qty: 200 }
{ "_id" : 3, "item" : "xyz1", description: "product 3", qty: 250 }
{ "_id" : 4, "item" : "VWZ1", description: "product 4", qty: 300 }
{ "_id" : 5, "item" : "VWZ2", description: "product 5", qty: 180 }
5 có nhỏ hơn hoặc bằng
{ "_id" : 1, "item" : "abc1", description: "product 1", qty: 300 }
{ "_id" : 2, "item" : "abc2", description: "product 2", qty: 200 }
{ "_id" : 3, "item" : "xyz1", description: "product 3", qty: 250 }
{ "_id" : 4, "item" : "VWZ1", description: "product 4", qty: 300 }
{ "_id" : 5, "item" : "VWZ2", description: "product 5", qty: 180 }
6:$lte operator to determine if
{ "_id" : 1, "item" : "abc1", description: "product 1", qty: 300 }
{ "_id" : 2, "item" : "abc2", description: "product 2", qty: 200 }
{ "_id" : 3, "item" : "xyz1", description: "product 3", qty: 250 }
{ "_id" : 4, "item" : "VWZ1", description: "product 4", qty: 300 }
{ "_id" : 5, "item" : "VWZ2", description: "product 5", qty: 180 }
5 is less than or equal to
{ "_id" : 1, "item" : "abc1", description: "product 1", qty: 300 }
{ "_id" : 2, "item" : "abc2", description: "product 2", qty: 200 }
{ "_id" : 3, "item" : "xyz1", description: "product 3", qty: 250 }
{ "_id" : 4, "item" : "VWZ1", description: "product 4", qty: 300 }
{ "_id" : 5, "item" : "VWZ2", description: "product 5", qty: 180 }
6:

db.inventory.aggregate[
[
{
$project:
{
item: 1,
qty: 1,
qtyLte250: { $lte: [ "$qty", 250 ] },
_id: 0
}
}
]
]

Hoạt động trả về các kết quả sau:

{ "item" : "abc1", "qty" : 300, "qtyLte250" : false }
{ "item" : "abc2", "qty" : 200, "qtyLte250" : true }
{ "item" : "xyz1", "qty" : 250, "qtyLte250" : true }
{ "item" : "VWZ1", "qty" : 300, "qtyLte250" : false }
{ "item" : "VWZ2", "qty" : 180, "qtyLte250" : true }

Tài liệu về nhà → Hướng dẫn sử dụng MongoDBMongoDB Manual

{ "_id" : 1, "item" : "abc1", description: "product 1", qty: 300 }
{ "_id" : 2, "item" : "abc2", description: "product 2", qty: 200 }
{ "_id" : 3, "item" : "xyz1", description: "product 3", qty: 250 }
{ "_id" : 4, "item" : "VWZ1", description: "product 4", qty: 300 }
{ "_id" : 5, "item" : "VWZ2", description: "product 5", qty: 180 }
7Comparing hai giá trị và trả về:

Compares two values and returns:

  • true khi giá trị đầu tiên lớn hơn hoặc tương đương với giá trị thứ hai.

  • { "_id" : 1, "item" : "abc1", description: "product 1", qty: 300 }
    { "_id" : 2, "item" : "abc2", description: "product 2", qty: 200 }
    { "_id" : 3, "item" : "xyz1", description: "product 3", qty: 250 }
    { "_id" : 4, "item" : "VWZ1", description: "product 4", qty: 300 }
    { "_id" : 5, "item" : "VWZ2", description: "product 5", qty: 180 }
    0 Khi giá trị thứ nhất nhỏ hơn giá trị thứ hai.

{ "_id" : 1, "item" : "abc1", description: "product 1", qty: 300 }
{ "_id" : 2, "item" : "abc2", description: "product 2", qty: 200 }
{ "_id" : 3, "item" : "xyz1", description: "product 3", qty: 250 }
{ "_id" : 4, "item" : "VWZ1", description: "product 4", qty: 300 }
{ "_id" : 5, "item" : "VWZ2", description: "product 5", qty: 180 }
7 so sánh cả giá trị và loại, sử dụng thứ tự so sánh BSON được chỉ định cho các giá trị của các loại khác nhau.
{ "_id" : 1, "item" : "abc1", description: "product 1", qty: 300 }
{ "_id" : 2, "item" : "abc2", description: "product 2", qty: 200 }
{ "_id" : 3, "item" : "xyz1", description: "product 3", qty: 250 }
{ "_id" : 4, "item" : "VWZ1", description: "product 4", qty: 300 }
{ "_id" : 5, "item" : "VWZ2", description: "product 5", qty: 180 }
7
compares both value and type, using the specified BSON comparison order for values of different types.

{ "_id" : 1, "item" : "abc1", description: "product 1", qty: 300 }
{ "_id" : 2, "item" : "abc2", description: "product 2", qty: 200 }
{ "_id" : 3, "item" : "xyz1", description: "product 3", qty: 250 }
{ "_id" : 4, "item" : "VWZ1", description: "product 4", qty: 300 }
{ "_id" : 5, "item" : "VWZ2", description: "product 5", qty: 180 }
7 có cú pháp sau: has the following syntax:

{ $gte: [ , ] }

Để biết thêm thông tin về biểu thức, xem biểu thức.

Xem xét bộ sưu tập

{ "_id" : 1, "item" : "abc1", description: "product 1", qty: 300 }
{ "_id" : 2, "item" : "abc2", description: "product 2", qty: 200 }
{ "_id" : 3, "item" : "xyz1", description: "product 3", qty: 250 }
{ "_id" : 4, "item" : "VWZ1", description: "product 4", qty: 300 }
{ "_id" : 5, "item" : "VWZ2", description: "product 5", qty: 180 }
3 với các tài liệu sau:

{ "_id" : 1, "item" : "abc1", description: "product 1", qty: 300 }
{ "_id" : 2, "item" : "abc2", description: "product 2", qty: 200 }
{ "_id" : 3, "item" : "xyz1", description: "product 3", qty: 250 }
{ "_id" : 4, "item" : "VWZ1", description: "product 4", qty: 300 }
{ "_id" : 5, "item" : "VWZ2", description: "product 5", qty: 180 }

Hoạt động sau sử dụng toán tử

{ "_id" : 1, "item" : "abc1", description: "product 1", qty: 300 }
{ "_id" : 2, "item" : "abc2", description: "product 2", qty: 200 }
{ "_id" : 3, "item" : "xyz1", description: "product 3", qty: 250 }
{ "_id" : 4, "item" : "VWZ1", description: "product 4", qty: 300 }
{ "_id" : 5, "item" : "VWZ2", description: "product 5", qty: 180 }
7 để xác định xem
{ "_id" : 1, "item" : "abc1", description: "product 1", qty: 300 }
{ "_id" : 2, "item" : "abc2", description: "product 2", qty: 200 }
{ "_id" : 3, "item" : "xyz1", description: "product 3", qty: 250 }
{ "_id" : 4, "item" : "VWZ1", description: "product 4", qty: 300 }
{ "_id" : 5, "item" : "VWZ2", description: "product 5", qty: 180 }
5 có lớn hơn hay bằng
{ "_id" : 1, "item" : "abc1", description: "product 1", qty: 300 }
{ "_id" : 2, "item" : "abc2", description: "product 2", qty: 200 }
{ "_id" : 3, "item" : "xyz1", description: "product 3", qty: 250 }
{ "_id" : 4, "item" : "VWZ1", description: "product 4", qty: 300 }
{ "_id" : 5, "item" : "VWZ2", description: "product 5", qty: 180 }
6:
{ "_id" : 1, "item" : "abc1", description: "product 1", qty: 300 }
{ "_id" : 2, "item" : "abc2", description: "product 2", qty: 200 }
{ "_id" : 3, "item" : "xyz1", description: "product 3", qty: 250 }
{ "_id" : 4, "item" : "VWZ1", description: "product 4", qty: 300 }
{ "_id" : 5, "item" : "VWZ2", description: "product 5", qty: 180 }
7
operator to determine if
{ "_id" : 1, "item" : "abc1", description: "product 1", qty: 300 }
{ "_id" : 2, "item" : "abc2", description: "product 2", qty: 200 }
{ "_id" : 3, "item" : "xyz1", description: "product 3", qty: 250 }
{ "_id" : 4, "item" : "VWZ1", description: "product 4", qty: 300 }
{ "_id" : 5, "item" : "VWZ2", description: "product 5", qty: 180 }
5 is greater than or equal to
{ "_id" : 1, "item" : "abc1", description: "product 1", qty: 300 }
{ "_id" : 2, "item" : "abc2", description: "product 2", qty: 200 }
{ "_id" : 3, "item" : "xyz1", description: "product 3", qty: 250 }
{ "_id" : 4, "item" : "VWZ1", description: "product 4", qty: 300 }
{ "_id" : 5, "item" : "VWZ2", description: "product 5", qty: 180 }
6:

db.inventory.aggregate[
[
{
$project:
{
item: 1,
qty: 1,
qtyGte250: { $gte: [ "$qty", 250 ] },
_id: 0
}
}
]
]

Hoạt động trả về các kết quả sau:

{ "item" : "abc1", "qty" : 300, "qtyGte250" : true }
{ "item" : "abc2", "qty" : 200, "qtyGte250" : false }
{ "item" : "xyz1", "qty" : 250, "qtyGte250" : true }
{ "item" : "VWZ1", "qty" : 300, "qtyGte250" : true }
{ "item" : "VWZ2", "qty" : 180, "qtyGte250" : false }

GTE và LTE MongoDB là gì?

Các toán tử so sánh MongoDB có thể được sử dụng để so sánh các giá trị trong một tài liệu.... Toán tử so sánh..

LTE trong MongoDB là gì?

Sự định nghĩa.$ lte chọn các tài liệu trong đó giá trị của trường nhỏ hơn hoặc bằng [nghĩa làselects the documents where the value of the field is less than or equal to [i.e.

Bài Viết Liên Quan

Chủ Đề