File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -105,3 +105,44 @@ The following example uses ``new Date()`` to return
105
105
106
106
- :ref:`BSON Date <document-bson-type-date>`
107
107
- :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
+ ]
You can’t perform that action at this time.
0 commit comments