Skip to content

Commit 426e49c

Browse files
jason-price-mongodbjason-price-mongodb
andauthored
DOCSP-21234 add date example (#1035) (#1044)
* DOCSP-21234-add-date-example * DOCSP-21234-add-date-example * DOCSP-21234-add-date-example * DOCSP-21234-add-date-example * DOCSP-21234-add-date-example * DOCSP-21234-add-date-example Co-authored-by: jason-price-mongodb <[email protected]> Co-authored-by: jason-price-mongodb <[email protected]>
1 parent a839f29 commit 426e49c

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

source/reference/method/Date.txt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,44 @@ The following example uses ``new Date()`` to return
105105

106106
- :ref:`BSON Date <document-bson-type-date>`
107107
- :ref:`mongo Shell Date <mongo-shell-date-type>`
108+
109+
Insert and Return ``ISODate`` Objects
110+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
111+
112+
You can specify dates as ``ISODate`` objects.
113+
114+
The following example creates a ``cakeSales`` collection with
115+
``ISODate`` objects in the ``orderDate`` field:
116+
117+
.. code-block:: javascript
118+
119+
db.cakeSales.insertMany( [
120+
{ _id: 0, type: "chocolate", orderDate: new ISODate("2020-05-18T14:10:30Z") },
121+
{ _id: 1, type: "strawberry", orderDate: new ISODate("2021-03-20T11:30:05Z") },
122+
{ _id: 2, type: "vanilla", orderDate: new ISODate("2021-01-15T06:31:15Z") }
123+
] )
124+
125+
The following example returns documents where the ``orderDate`` is less
126+
than the ``ISODate`` specified in the :expression:`$lt` operator:
127+
128+
.. code-block:: javascript
129+
130+
db.cakeSales.find( { orderDate: { $lt: ISODate("2021-02-25T10:03:46.000Z") } } )
131+
132+
Example output:
133+
134+
.. code-block:: javascript
135+
:copyable: false
136+
137+
[
138+
{
139+
_id: 0,
140+
type: 'chocolate',
141+
orderDate: ISODate("2020-05-18T14:10:30.000Z")
142+
},
143+
{
144+
_id: 2,
145+
type: 'vanilla',
146+
orderDate: ISODate("2021-01-15T06:31:15.000Z")
147+
}
148+
]

0 commit comments

Comments
 (0)