From 9966c09cff444ae76833f1eee7bc427cf9b68f6b Mon Sep 17 00:00:00 2001 From: Lindsey Moore <lindsey.moore@mongodb.com> Date: Tue, 8 Apr 2025 10:14:41 -0400 Subject: [PATCH 1/8] DOCSP-48717 UUID --- source/data-formats/uuid.txt | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 source/data-formats/uuid.txt diff --git a/source/data-formats/uuid.txt b/source/data-formats/uuid.txt new file mode 100644 index 000000000..c62d3f7a3 --- /dev/null +++ b/source/data-formats/uuid.txt @@ -0,0 +1,31 @@ +.. _node-uuid: + +============================== +Universally Unique IDs (UUIDs) +============================== + +.. contents:: On this page + :local: + :backlinks: none + :depth: 2 + :class: singlecol + +.. facet:: + :name: genre + :values: reference + +.. meta:: + :keywords: encode, decode, bson, binary, code examples + +Overview +-------- + +MongoDB drivers have historically differed in how they encode +**universally unique identifiers** (UUIDs). In this guide, you can learn how to use +{+driver-short+}'s ``UuidRepresentation`` configuration option to maintain cross-language +compatibility when working with UUIDs. + +.. tip:: + + In MongoDB applications, you can use the ``ObjectId`` type as a unique identifier for + a document. Consider using ``ObjectId`` in place of a UUID where possible. \ No newline at end of file From 6e1a02a915525e3fb9fdcb2f1c687f6839d53cc7 Mon Sep 17 00:00:00 2001 From: Lindsey Moore <lindsey.moore@mongodb.com> Date: Tue, 8 Apr 2025 17:18:29 -0400 Subject: [PATCH 2/8] DOCSP-49031 UUID --- source/data-formats/bson.txt | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/source/data-formats/bson.txt b/source/data-formats/bson.txt index 25fd0f948..3346c4d44 100644 --- a/source/data-formats/bson.txt +++ b/source/data-formats/bson.txt @@ -20,11 +20,8 @@ In this guide, you can learn how to create BSON documents, read BSON from a file and write BSON to a file by using the {+driver-short+}. **BSON**, or Binary JSON, is the data format that MongoDB uses to organize -and store data. This data format includes all JSON data structure types and -adds support for types including dates, different size integers, ObjectIds, and -binary data. You can use BSON documents in your {+language+} application by importing the -BSON package. For a complete list of supported types, see the -:manual:`BSON Types </reference/bson-types>` server manual page. +and store data. You can use BSON documents in your {+language+} application +by importing the BSON package. The code samples in this guide use the following BSON document as an example: @@ -40,6 +37,27 @@ The code samples in this guide use the following BSON document as an example: "name" : "Mongo's Pizza" } +BSON Data Types +--------------- + +BSON supports all JSON data structure types and adds support for types including +dates, different size integers, ObjectIds, and binary data. For a complete list of +supported types, see the :manual:`BSON Types </reference/bson-types>` server +manual page. + +Universally Unique IDs (UUIDs) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The {+driver-short+} has a BSON Binary subclass for UUIDs. You can create a UUID +object by using the ``UUID()`` method. The following code example generates a random +UUID: + +.. code-block:: javascript + + import { BSON } from 'bson'; + + const myUuid = new BSON.UUID(); + Create a BSON Document ---------------------- @@ -137,5 +155,7 @@ API Documentation ----------------- To learn more about any of the methods or types discussed in this -guide, see the `BSON <{+api+}/modules/BSON.html>`__ API documentation. +guide, see the following API documentation: +- `BSON <{+api+}/modules/BSON.html>`__ +- `UUID <{+api+}/classes/BSON.UUID.html>`__ From c349127e485d473fd26dd082621687c0bc63c2c7 Mon Sep 17 00:00:00 2001 From: Lindsey Moore <lindsey.moore@mongodb.com> Date: Tue, 8 Apr 2025 17:35:50 -0400 Subject: [PATCH 3/8] edits --- source/data-formats/bson.txt | 6 +++--- source/data-formats/uuid.txt | 31 ------------------------------- 2 files changed, 3 insertions(+), 34 deletions(-) delete mode 100644 source/data-formats/uuid.txt diff --git a/source/data-formats/bson.txt b/source/data-formats/bson.txt index 3346c4d44..d54b9824f 100644 --- a/source/data-formats/bson.txt +++ b/source/data-formats/bson.txt @@ -48,9 +48,9 @@ manual page. Universally Unique IDs (UUIDs) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -The {+driver-short+} has a BSON Binary subclass for UUIDs. You can create a UUID -object by using the ``UUID()`` method. The following code example generates a random -UUID: +The {+driver-short+} supports UUIDs with the BSON Binary subclass ``UUID``. You +can create a ``UUID`` object by using the ``UUID()`` method. The following code +example generates a random UUID: .. code-block:: javascript diff --git a/source/data-formats/uuid.txt b/source/data-formats/uuid.txt deleted file mode 100644 index c62d3f7a3..000000000 --- a/source/data-formats/uuid.txt +++ /dev/null @@ -1,31 +0,0 @@ -.. _node-uuid: - -============================== -Universally Unique IDs (UUIDs) -============================== - -.. contents:: On this page - :local: - :backlinks: none - :depth: 2 - :class: singlecol - -.. facet:: - :name: genre - :values: reference - -.. meta:: - :keywords: encode, decode, bson, binary, code examples - -Overview --------- - -MongoDB drivers have historically differed in how they encode -**universally unique identifiers** (UUIDs). In this guide, you can learn how to use -{+driver-short+}'s ``UuidRepresentation`` configuration option to maintain cross-language -compatibility when working with UUIDs. - -.. tip:: - - In MongoDB applications, you can use the ``ObjectId`` type as a unique identifier for - a document. Consider using ``ObjectId`` in place of a UUID where possible. \ No newline at end of file From 56c3dee7f754ea9a0b57b304fb832cd393ca7b81 Mon Sep 17 00:00:00 2001 From: Lindsey Moore <lindsey.moore@mongodb.com> Date: Tue, 8 Apr 2025 17:40:09 -0400 Subject: [PATCH 4/8] edit import --- source/data-formats/bson.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/data-formats/bson.txt b/source/data-formats/bson.txt index d54b9824f..2c51467f2 100644 --- a/source/data-formats/bson.txt +++ b/source/data-formats/bson.txt @@ -54,7 +54,7 @@ example generates a random UUID: .. code-block:: javascript - import { BSON } from 'bson'; + import { BSON } from 'mongodb'; const myUuid = new BSON.UUID(); From 1f15f532c31d46f2ed7cad2172a6e99d517c75a0 Mon Sep 17 00:00:00 2001 From: Lindsey Moore <lindsey.moore@mongodb.com> Date: Tue, 8 Apr 2025 17:46:29 -0400 Subject: [PATCH 5/8] edit --- source/data-formats/bson.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/data-formats/bson.txt b/source/data-formats/bson.txt index 2c51467f2..79166f73d 100644 --- a/source/data-formats/bson.txt +++ b/source/data-formats/bson.txt @@ -42,8 +42,8 @@ BSON Data Types BSON supports all JSON data structure types and adds support for types including dates, different size integers, ObjectIds, and binary data. For a complete list of -supported types, see the :manual:`BSON Types </reference/bson-types>` server -manual page. +supported types, see the :manual:`BSON Types </reference/bson-types>` page in the +Server Manual. Universally Unique IDs (UUIDs) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ From a1d4923b4c4abc340d1ca652724798f5ba0ede2f Mon Sep 17 00:00:00 2001 From: Lindsey Moore <lindsey.moore@mongodb.com> Date: Tue, 8 Apr 2025 17:51:55 -0400 Subject: [PATCH 6/8] edit --- source/data-formats/bson.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/data-formats/bson.txt b/source/data-formats/bson.txt index 79166f73d..84aec703a 100644 --- a/source/data-formats/bson.txt +++ b/source/data-formats/bson.txt @@ -48,7 +48,7 @@ Server Manual. Universally Unique IDs (UUIDs) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -The {+driver-short+} supports UUIDs with the BSON Binary subclass ``UUID``. You +The {+driver-short+} supports UUIDs by using the BSON Binary subclass ``UUID``. You can create a ``UUID`` object by using the ``UUID()`` method. The following code example generates a random UUID: From e9b87de861b35f55c8b1acb456696c8fb75c5b1c Mon Sep 17 00:00:00 2001 From: Lindsey Moore <lindsey.moore@mongodb.com> Date: Wed, 9 Apr 2025 16:08:01 -0400 Subject: [PATCH 7/8] JS review --- source/data-formats/bson.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/data-formats/bson.txt b/source/data-formats/bson.txt index 84aec703a..a630dde19 100644 --- a/source/data-formats/bson.txt +++ b/source/data-formats/bson.txt @@ -41,9 +41,9 @@ BSON Data Types --------------- BSON supports all JSON data structure types and adds support for types including -dates, different size integers, ObjectIds, and binary data. For a complete list of +dates, different size integers, ``ObjectId``, and binary data. For a complete list of supported types, see the :manual:`BSON Types </reference/bson-types>` page in the -Server Manual. +{+mdb-server+} Manual. Universally Unique IDs (UUIDs) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ From e5591ae58aec16be1d802f07d44cbe09a228d3d9 Mon Sep 17 00:00:00 2001 From: Lindsey Moore <lindsey.moore@mongodb.com> Date: Fri, 11 Apr 2025 15:38:27 -0400 Subject: [PATCH 8/8] tech review --- source/data-formats/bson.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/data-formats/bson.txt b/source/data-formats/bson.txt index a630dde19..bef850a93 100644 --- a/source/data-formats/bson.txt +++ b/source/data-formats/bson.txt @@ -49,12 +49,12 @@ Universally Unique IDs (UUIDs) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The {+driver-short+} supports UUIDs by using the BSON Binary subclass ``UUID``. You -can create a ``UUID`` object by using the ``UUID()`` method. The following code +can create a ``UUID`` object by using the ``UUID()`` constructor. The following code example generates a random UUID: .. code-block:: javascript - import { BSON } from 'mongodb'; + import { UUID } from 'mongodb'; const myUuid = new BSON.UUID();