Skip to content

Commit 6a9ff93

Browse files
author
Dave
authored
DOCSP-19964 update insert pt6 v5.1 (#102) (#105)
* DOCSP-19964 update insert pt6 * Add files * Staging updates
1 parent b571ef1 commit 6a9ff93

File tree

10 files changed

+154
-99
lines changed

10 files changed

+154
-99
lines changed

source/reference/operator/aggregation/toDouble.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ Create a collection ``weather`` with the following documents:
134134

135135
.. code-block:: javascript
136136

137-
db.weather.insert( [
137+
db.weather.insertMany( [
138138
{ _id: 1, date: new Date("2018-06-01"), temp: "26.1C" },
139139
{ _id: 2, date: new Date("2018-06-02"), temp: "25.1C" },
140140
{ _id: 3, date: new Date("2018-06-03"), temp: "25.4C" },
@@ -156,7 +156,7 @@ parses the ``temp`` value and converts to a double:
156156

157157
db.weather.aggregate( [
158158
tempConversionStage,
159-
])
159+
] )
160160

161161
The operation returns the following documents:
162162

@@ -172,3 +172,4 @@ The operation returns the following documents:
172172
If the conversion operation encounters an error, the aggregation
173173
operation stops and throws an error. To override this behavior, use
174174
:expression:`$convert` instead.
175+

source/reference/operator/aggregation/toInt.txt

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -152,16 +152,18 @@ Create a collection ``orders`` with the following documents:
152152

153153
.. code-block:: javascript
154154

155-
db.orders.insert( [
156-
{ _id: 1, item: "apple", qty: 5, price: 10 },
157-
{ _id: 2, item: "pie", qty: 10, price: NumberDecimal("20.0") },
158-
{ _id: 3, item: "ice cream", qty: 2, price: "4.99" },
159-
{ _id: 4, item: "almonds" , qty: 5, price: 5 }
155+
db.orders.insertMany( [
156+
{ _id: 1, item: "apple", qty: "5", price: 10 },
157+
{ _id: 2, item: "pie", qty: "10", price: NumberDecimal("20.0") },
158+
{ _id: 3, item: "ice cream", qty: "2", price: "4.99" },
159+
{ _id: 4, item: "almonds" , qty: "5", price: 5 }
160160
] )
161161

162-
The following aggregation operation on the ``orders`` collection
163-
converts the ``qty`` to an integer as well as convert ``price`` to a
164-
decimal before calculating the total price:
162+
The following aggregation operation:
163+
164+
- converts ``qty`` to an integer,
165+
- converts ``price`` to a decimal,
166+
- calculates the total price:
165167

166168
.. code-block:: javascript
167169

@@ -184,16 +186,16 @@ decimal before calculating the total price:
184186
db.orders.aggregate( [
185187
priceQtyConversionStage,
186188
totalPriceCalculationStage
187-
])
189+
] )
188190

189191
The operation returns the following documents:
190192

191193
.. code-block:: javascript
192194

193-
{ "_id" : 1, "item" : "apple", "totalPrice" : NumberDecimal("50.0000000000000") }
194-
{ "_id" : 2, "item" : "pie", "totalPrice" : NumberDecimal("200.0") }
195-
{ "_id" : 3, "item" : "ice cream", "totalPrice" : NumberDecimal("9.98") }
196-
{ "_id" : 4, "item" : "almonds", "totalPrice" : NumberDecimal("25.00000000000000") }
195+
{ _id: 1, item: 'apple', totalPrice: Decimal128("50") },
196+
{ _id: 2, item: 'pie', totalPrice: Decimal128("200.0") },
197+
{ _id: 3, item: 'ice cream', totalPrice: Decimal128("9.98") },
198+
{ _id: 4, item: 'almonds', totalPrice: Decimal128("25") }
197199

198200
.. note::
199201

source/reference/operator/aggregation/toLong.txt

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ long:
6464
- Behavior
6565

6666
* - Boolean
67-
- | Returns NumberLong(0) for ``false``.
68-
| Returns NumberLong(1) for ``true``.
67+
- | Returns Long(0) for ``false``.
68+
| Returns Long(1) for ``true``.
6969

7070

7171
* - Double
@@ -114,34 +114,34 @@ The following table lists some conversion to long examples:
114114

115115
.. list-table::
116116
:header-rows: 1
117-
:widths: 80 20
117+
:widths: 67 33
118118

119119
* - Example
120120
- Results
121121

122122
* - ``{ $toLong: true }``
123-
- NumberLong("1")
123+
- Long("1")
124124

125125
* - ``{ $toLong: false }``
126-
- NumberLong("0")
126+
- Long("0")
127127

128128
* - ``{ $toLong: 1.99999 }``
129-
- NumberLong("1")
129+
- Long("1")
130130

131131
* - ``{ $toLong: NumberDecimal("5.5000") }``
132-
- NumberLong("5")
132+
- Long("5")
133133

134134
* - ``{ $toLong: NumberDecimal("9223372036854775808.0") }``
135135
- Error
136136

137137
* - ``{ $toLong: NumberInt(8) }``
138-
- NumberLong(8)
138+
- Long(8)
139139

140140
* - ``{ $toLong: ISODate("2018-03-26T04:38:28.044Z") }``
141-
- NumberLong("1522039108044")
141+
- Long("1522039108044")
142142

143143
* - ``{ $toLong: "-2" }``
144-
- NumberLong("-2")
144+
- Long("-2")
145145

146146
* - ``{ $toLong: "2.5" }``
147147
- Error
@@ -156,10 +156,10 @@ Create a collection ``orders`` with the following documents:
156156

157157
.. code-block:: javascript
158158

159-
db.orders.insert( [
159+
db.orders.insertMany( [
160160
{ _id: 1, item: "apple", qty: NumberInt(5) },
161161
{ _id: 2, item: "pie", qty: "100" },
162-
{ _id: 3, item: "ice cream", qty: NumberLong(500) },
162+
{ _id: 3, item: "ice cream", qty: NumberLong("500") },
163163
{ _id: 4, item: "almonds", qty: "50" },
164164
] )
165165

@@ -192,13 +192,14 @@ The operation returns the following documents:
192192

193193
.. code-block:: javascript
194194

195-
{ "_id" : 1, "item" : "apple", "qty" : 5, "convertedQty" : NumberLong(5) }
196-
{ "_id" : 2, "item" : "pie", "qty" : "100", "convertedQty" : NumberLong(100) }
197-
{ "_id" : 3, "item" : "ice cream", "qty" : NumberLong(500), "convertedQty" : NumberLong(500) }
198-
{ "_id" : 4, "item" : "almonds", "qty" : "50", "convertedQty" : NumberLong(50) }
195+
{ _id: 3, item: 'ice cream', qty: Long("500"), convertedQty: Long("500") },
196+
{ _id: 2, item: 'pie', qty: '100', convertedQty: Long("100") },
197+
{ _id: 4, item: 'almonds', qty: '50', convertedQty: Long("50") },
198+
{ _id: 1, item: 'apple', qty: 5, convertedQty: Long("5") }
199199

200200
.. note::
201201

202202
If the conversion operation encounters an error, the aggregation
203203
operation stops and throws an error. To override this behavior, use
204204
:expression:`$convert` instead.
205+

source/reference/operator/aggregation/toObjectId.txt

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ The following table lists some conversion to date examples:
7070

7171
.. list-table::
7272
:header-rows: 1
73-
:widths: 80 20
73+
:widths: 67 33
7474

7575
* - Example
7676
- Results
@@ -89,7 +89,7 @@ Create a collection ``orders`` with the following documents:
8989

9090
.. code-block:: javascript
9191

92-
db.orders.insert( [
92+
db.orders.insertMany( [
9393
{ _id: "5ab9cbe531c2ab715d42129a", item: "apple", qty: 10 },
9494
{ _id: ObjectId("5ab9d0b831c2ab715d4212a8"), item: "pie", qty: 5 },
9595
{ _id: ObjectId("5ab9d2d331c2ab715d4212b3"), item: "ice cream", qty: 20 },
@@ -119,19 +119,40 @@ converts the ``_id`` to ObjectId before sorting by the value:
119119
db.orders.aggregate( [
120120
idConversionStage,
121121
sortStage
122-
])
122+
] )
123123

124124
The operation returns the following documents:
125125

126126
.. code-block:: javascript
127127

128-
{ "_id" : "5ab9e16431c2ab715d4212b4", "item" : "almonds", "qty" : 50, "convertedId" : ObjectId("5ab9e16431c2ab715d4212b4") }
129-
{ "_id" : ObjectId("5ab9d2d331c2ab715d4212b3"), "item" : "ice cream", "qty" : 20, "convertedId" : ObjectId("5ab9d2d331c2ab715d4212b3") }
130-
{ "_id" : ObjectId("5ab9d0b831c2ab715d4212a8"), "item" : "pie", "qty" : 5, "convertedId" : ObjectId("5ab9d0b831c2ab715d4212a8") }
131-
{ "_id" : "5ab9cbe531c2ab715d42129a", "item" : "apple", "qty" : 10, "convertedId" : ObjectId("5ab9cbe531c2ab715d42129a") }
128+
{
129+
_id: '5ab9e16431c2ab715d4212b4',
130+
item: 'almonds',
131+
qty: 50,
132+
convertedId: ObjectId("5ab9e16431c2ab715d4212b4")
133+
},
134+
{
135+
_id: ObjectId("5ab9d2d331c2ab715d4212b3"),
136+
item: 'ice cream',
137+
qty: 20,
138+
convertedId: ObjectId("5ab9d2d331c2ab715d4212b3")
139+
},
140+
{
141+
_id: ObjectId("5ab9d0b831c2ab715d4212a8"),
142+
item: 'pie',
143+
qty: 5,
144+
convertedId: ObjectId("5ab9d0b831c2ab715d4212a8")
145+
},
146+
{
147+
_id: '5ab9cbe531c2ab715d42129a',
148+
item: 'apple',
149+
qty: 10,
150+
convertedId: ObjectId("5ab9cbe531c2ab715d42129a")
151+
}
132152

133153
.. note::
134154

135155
If the conversion operation encounters an error, the aggregation
136156
operation stops and throws an error. To override this behavior, use
137157
:expression:`$convert` instead.
158+

source/reference/operator/aggregation/toString.txt

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,11 @@ Create a collection ``orders`` with the following documents:
122122

123123
.. code-block:: javascript
124124

125-
db.orders.insert( [
126-
{ _id: 1, item: "apple", qty: 5, zipcode: 12345 },
127-
{ _id: 2, item: "pie", qty: 10, zipcode: 11111 },
128-
{ _id: 3, item: "ice cream", zipcode: "12345" },
129-
{ _id: 4, item: "almonds", qty: 2, zipcode: "12345-0030" },
130-
])
125+
db.orders.insertMany( [
126+
{ _id: 1, item: "apple", qty: 5, zipcode: 93445 },
127+
{ _id: 2, item: "almonds", qty: 2, zipcode: "12345-0030" },
128+
{ _id: 3, item: "peaches", qty: 5, zipcode: 12345 },
129+
] )
131130

132131
The following aggregation operation on the ``orders`` collection
133132
converts the ``zipcode`` to string before sorting by the string value:
@@ -151,19 +150,37 @@ converts the ``zipcode`` to string before sorting by the string value:
151150
db.orders.aggregate( [
152151
zipConversionStage,
153152
sortStage
154-
])
153+
] )
155154

156155
The operation returns the following documents:
157156

158157
.. code-block:: javascript
159158

160-
{ "_id" : 2, "item" : "pie", "qty" : 10, "zipcode" : 11111, "convertedZipCode" : "11111" }
161-
{ "_id" : 1, "item" : "apple", "qty" : 5, "zipcode" : 12345, "convertedZipCode" : "12345" }
162-
{ "_id" : 3, "item" : "ice cream", "zipcode" : "12345", "convertedZipCode" : "12345" }
163-
{ "_id" : 4, "item" : "almonds", "qty" : 2, "zipcode" : "12345-0030", "convertedZipCode" : "12345-0030" }
159+
{
160+
_id: 3,
161+
item: 'peaches',
162+
qty: 5,
163+
zipcode: 12345,
164+
convertedZipCode: '12345'
165+
},
166+
{
167+
_id: 2,
168+
item: 'almonds',
169+
qty: 2,
170+
zipcode: '12345-0030',
171+
convertedZipCode: '12345-0030'
172+
},
173+
{
174+
_id: 1,
175+
item: 'apple',
176+
qty: 5,
177+
zipcode: 93445,
178+
convertedZipCode: '93445'
179+
}
164180

165181
.. note::
166182

167183
If the conversion operation encounters an error, the aggregation
168184
operation stops and throws an error. To override this behavior, use
169185
:expression:`$convert` instead.
186+

source/reference/operator/query/jsonSchema.txt

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ Definition
1515

1616
.. query:: $jsonSchema
1717

18-
.. versionadded:: 3.6
19-
2018
The :query:`$jsonSchema` operator matches documents that satisfy
2119
the specified JSON Schema.
2220

@@ -175,59 +173,65 @@ operator to set schema validation rules:
175173
}
176174
}
177175
}
178-
})
176+
} )
179177

180178
Given the created ``validator`` for the collection, the following insert
181179
operation will fail because ``gpa`` is an integer when the ``validator``
182180
requires a ``double``.
183181

184182
.. code-block:: javascript
185183

186-
db.students.insert({
184+
db.students.insertOne( {
187185
name: "Alice",
188-
year: NumberInt(2019),
186+
year: Int32( 2019 ),
189187
major: "History",
190-
gpa: NumberInt(3),
188+
gpa: Int32( 3 ),
191189
address: {
192190
city: "NYC",
193191
street: "33rd Street"
194192
}
195-
})
193+
} )
196194

197195
The operation returns the following error:
198196

199197
.. code-block:: javascript
200198
:copyable: false
201199

202-
WriteResult({
203-
"nInserted" : 0,
204-
"writeError" : {
205-
"code" : 121,
206-
"errmsg" : "Document failed validation"
207-
}
208-
})
200+
MongoServerError: Document failed validation
201+
Additional information: {
202+
failingDocumentId: ObjectId("61aa577f666a50a8fccd7ec2"),
203+
details: {
204+
operatorName: '$jsonSchema',
205+
schemaRulesNotSatisfied: [
206+
{
207+
operatorName: 'properties',
208+
propertiesNotSatisfied: [
209+
{
210+
propertyName: 'gpa',
211+
description: 'must be a double if the field exists',
212+
details: [ [Object] ]
213+
}
214+
]
215+
}
216+
]
217+
}
218+
}
219+
209220

210221
After changing the ``gpa`` to a double, the insert succeeds:
211222

212223
.. code-block:: javascript
213224

214-
db.students.insert({
225+
db.students.insertOne( {
215226
name: "Alice",
216227
year: NumberInt(2019),
217228
major: "History",
218-
gpa: 3.0,
229+
gpa: Double(3.0),
219230
address: {
220231
city: "NYC",
221232
street: "33rd Street"
222233
}
223-
})
224-
225-
The operation returns the following:
226-
227-
.. code-block:: javascript
228-
:copyable: false
229-
230-
WriteResult({ "nInserted" : 1 })
234+
} )
231235

232236
Query Conditions
233237
~~~~~~~~~~~~~~~~
@@ -241,15 +245,15 @@ following documents:
241245

242246
.. code-block:: javascript
243247

244-
db.inventory.insertMany([
248+
db.inventory.insertMany( [
245249
{ item: "journal", qty: NumberInt(25), size: { h: 14, w: 21, uom: "cm" }, instock: true },
246250
{ item: "notebook", qty: NumberInt(50), size: { h: 8.5, w: 11, uom: "in" }, instock: true },
247251
{ item: "paper", qty: NumberInt(100), size: { h: 8.5, w: 11, uom: "in" }, instock: 1 },
248252
{ item: "planner", qty: NumberInt(75), size: { h: 22.85, w: 30, uom: "cm" }, instock: 1 },
249253
{ item: "postcard", qty: NumberInt(45), size: { h: 10, w: 15.25, uom: "cm" }, instock: true },
250254
{ item: "apple", qty: NumberInt(45), status: "A", instock: true },
251255
{ item: "pears", qty: NumberInt(50), status: "A", instock: true }
252-
])
256+
] )
253257

254258
Next, define the following sample schema object:
255259

0 commit comments

Comments
 (0)