You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
new Document("title", "One Hundred Years of Solitude").append("yearPublished", 1967),
122
-
new Document("title", "Chronicle of a Death Foretold").append("yearPublished", 1981),
123
-
new Document("title", "Love in the Time of Cholera").append("yearPublished", 1985)));
122
+
new Document("title", "One Hundred Years of Solitude")
123
+
.append("yearPublished", 1967),
124
+
new Document("title", "Chronicle of a Death Foretold")
125
+
.append("yearPublished", 1981),
126
+
new Document("title", "Love in the Time of Cholera")
127
+
.append("yearPublished", 1985)));
124
128
125
129
To insert this document into a collection, instantiate a collection
126
130
using the ``getCollection()`` method and call the :doc:`insertOne
@@ -228,11 +232,16 @@ different field types:
228
232
BsonDocument author = new BsonDocument()
229
233
.append("_id", new BsonObjectId())
230
234
.append("name", new BsonString("Gabriel García Márquez"))
231
-
.append("dateOfDeath", new BsonDateTime(LocalDate.of(2014, 4, 17).atStartOfDay(ZoneId.systemDefault()).toInstant().toEpochMilli()))
235
+
.append("dateOfDeath",
236
+
new BsonDateTime(LocalDate.of(2014, 4, 17).atStartOfDay(ZoneId.systemDefault())
237
+
.toInstant().toEpochMilli()))
232
238
.append("novels", new BsonArray(Arrays.asList(
233
-
new BsonDocument().append("title", new BsonString("One Hundred Years of Solitude")).append("yearPublished", new BsonInt32(1967)),
234
-
new BsonDocument().append("title", new BsonString("Chronicle of a Death Foretold")).append("yearPublished", new BsonInt32(1981)),
235
-
new BsonDocument().append("title", new BsonString("Love in the Time of Cholera")).append("yearPublished", new BsonInt32(1985))
239
+
new BsonDocument().append("title", new BsonString("One Hundred Years of Solitude"))
240
+
.append("yearPublished", new BsonInt32(1967)),
241
+
new BsonDocument().append("title", new BsonString("Chronicle of a Death Foretold"))
242
+
.append("yearPublished", new BsonInt32(1981)),
243
+
new BsonDocument().append("title", new BsonString("Love in the Time of Cholera"))
244
+
.append("yearPublished", new BsonInt32(1985))
236
245
)));
237
246
238
247
To insert this document into a collection, instantiate a collection
@@ -359,7 +368,11 @@ The output of the preceding code resembles the following:
359
368
.. code-block:: none
360
369
:copyable: false
361
370
362
-
query result in extended json format: {"_id": {"$oid": "6035210f35bd203721c3eab8"}, "name": "Gabriel García Márquez", "dateOfDeath": {"$date": "2014-04-17T04:00:00Z"}, "novels": [{"title": "One Hundred Years of Solitude", "yearPublished": 1967}, {"title": "Chronicle of a Death Foretold", "yearPublished": 1981}, {"title": "Love in the Time of Cholera", "yearPublished": 1985}]}
371
+
query result in extended json format: {"_id": {"$oid": "6035210f35bd203721c3eab8"},
372
+
"name": "Gabriel García Márquez", "dateOfDeath": {"$date": "2014-04-17T04:00:00Z"},
373
+
"novels": [{"title": "One Hundred Years of Solitude", "yearPublished": 1967},
374
+
{"title": "Chronicle of a Death Foretold", "yearPublished": 1981},
375
+
{"title": "Love in the Time of Cholera", "yearPublished": 1985}]}
363
376
364
377
.. tip::
365
378
@@ -394,7 +407,8 @@ The output of the preceding code resembles the following:
394
407
JsonObject author = new JsonObject("{\"_id\": \"6035210f35bd203721c3eab8\", "
+ "\"novels\": [{\"title\": \"One Hundred Years of Solitude\", \"yearPublished\": 1967}, {\"title\": \"Chronicle of a Death Foretold\", \"yearPublished\": 1981}, "
410
+
+ "\"novels\": [{\"title\": \"One Hundred Years of Solitude\", \"yearPublished\": 1967},
411
+
{\"title\": \"Chronicle of a Death Foretold\", \"yearPublished\": 1981}, "
398
412
+ "{\"title\": \"Love in the Time of Cholera\", \"yearPublished\": 1985}]}\n");
399
413
collection.insertOne(author);
400
414
JsonObject query = new JsonObject("{\"name\": \"Gabriel Garc\\u00eda M\\u00e1rquez\"}");
@@ -408,7 +422,10 @@ The output of the preceding code resembles the following:
408
422
.. code-block:: none
409
423
:copyable: false
410
424
411
-
query result in relaxed json format: {"_id": "6035210f35bd203721c3eab8", "name": "Gabriel García Márquez", "dateOfDeath": {"$date": "2014-04-17T04:00:00Z"}, "novels": [{"title": "One Hundred Years of Solitude", "yearPublished": 1967}, {"title": "Chronicle of a Death Foretold", "yearPublished": 1981}, {"title": "Love in the Time of Cholera", "yearPublished": 1985}]}
425
+
query result in relaxed json format: {"_id": "6035210f35bd203721c3eab8", "name": "Gabriel García Márquez",
426
+
"dateOfDeath": {"$date": "2014-04-17T04:00:00Z"}, "novels": [{"title": "One Hundred Years of Solitude",
427
+
"yearPublished": 1967}, {"title": "Chronicle of a Death Foretold", "yearPublished": 1981},
428
+
{"title": "Love in the Time of Cholera", "yearPublished": 1985}]}
412
429
413
430
For more information about the methods and classes mentioned in this section,
414
431
see the following API Documentation:
@@ -442,11 +459,15 @@ different field types:
442
459
443
460
BasicDBObject author = new BasicDBObject("_id", new ObjectId())
0 commit comments