/
gte.txt
75 lines (53 loc) · 1.88 KB
/
gte.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
==================
$gte (aggregation)
==================
.. default-domain:: mongodb
.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: singlecol
Definition
----------
.. expression:: $gte
Compares two values and returns:
- ``true`` when the first value is *greater than or equivalent* to the
second value.
- ``false`` when the first value is *less than* the second value.
.. include:: /includes/extracts/fact-agg-comparison-expression-gte.rst
:expression:`$gte` has the following syntax:
.. code-block:: javascript
{ $gte: [ <expression1>, <expression2> ] }
For more information on expressions, see :ref:`aggregation-expressions`.
Example
-------
Consider an ``inventory`` collection with the following documents:
.. code-block:: javascript
{ "_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 }
The following operation uses the :expression:`$gte` operator to
determine if ``qty`` is greater than or equal to ``250``:
.. code-block:: javascript
db.inventory.aggregate(
[
{
$project:
{
item: 1,
qty: 1,
qtyGte250: { $gte: [ "$qty", 250 ] },
_id: 0
}
}
]
)
The operation returns the following results:
.. code-block:: javascript
{ "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 }