Skip to content

DOCSP-49031 UUID #1072

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 14, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions source/data-formats/bson.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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, ``ObjectId``, and binary data. For a complete list of
supported types, see the :manual:`BSON Types </reference/bson-types>` page in the
{+mdb-server+} Manual.

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()`` constructor. The following code
example generates a random UUID:

.. code-block:: javascript

import { UUID } from 'mongodb';

const myUuid = new BSON.UUID();

Create a BSON Document
----------------------

Expand Down Expand Up @@ -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>`__