|
| 1 | +.. _kotlin-sync-bson: |
| 2 | + |
| 3 | +========================== |
| 4 | +Document Data Format: BSON |
| 5 | +========================== |
| 6 | + |
| 7 | +.. contents:: On this page |
| 8 | + :local: |
| 9 | + :backlinks: none |
| 10 | + :depth: 2 |
| 11 | + :class: singlecol |
| 12 | + |
| 13 | +Overview |
| 14 | +-------- |
| 15 | + |
| 16 | +In this guide, you can learn about the BSON data format, how MongoDB |
| 17 | +uses BSON to organize and store data, and how to install the BSON library independently of |
| 18 | +the {+driver-short+}. |
| 19 | + |
| 20 | +BSON Data Format |
| 21 | +---------------- |
| 22 | + |
| 23 | +**BSON**, or Binary JSON, is the data format that MongoDB uses to organize |
| 24 | +and store data. This data format includes all JSON data structure types and |
| 25 | +adds support for types including dates, differently-sized integers (32-bit and 64-bit), |
| 26 | +ObjectIds, and binary data. For a complete list of supported types, see the |
| 27 | +:manual:`BSON Types </reference/bson-types>` in the {+mdb-server+} documentation. |
| 28 | + |
| 29 | +BSON is not human-readable, but you can use the |
| 30 | +:ref:`BSON library <install-bson-library>` to convert it to the human-readable JSON |
| 31 | +representation. You can read more about the relationship between these |
| 32 | +formats in the :website:`JSON and BSON </json-and-bson>` guide on the MongoDB website. |
| 33 | + |
| 34 | +MongoDB and BSON |
| 35 | +---------------- |
| 36 | + |
| 37 | +You can work with BSON data in your {+driver-short+} application by using one of the |
| 38 | +following object types that implements the `BSON interface <{+java-api+}/apidocs/bson/org/bson/conversions/Bson.html>`__: |
| 39 | + |
| 40 | +- `Document <{+java-api+}/apidocs/bson/org/bson/Document.html>`__ (BSON library package) |
| 41 | +- `BsonDocument <{+java-api+}/apidocs/bson/org/bson/BsonDocument.html>`__ (BSON library package) |
| 42 | +- `RawBsonDocument <{+java-api+}/apidocs/bson/org/bson/RawBsonDocument.html>`__ (BSON library package) |
| 43 | +- `JsonObject <{+java-api+}/apidocs/bson/org/bson/json/JsonObject.html>`__ (BSON library package) |
| 44 | + |
| 45 | +.. _install-bson-library: |
| 46 | + |
| 47 | +Install the BSON Library |
| 48 | +------------------------ |
| 49 | + |
| 50 | +These instructions detail how to add the BSON library as a dependency to |
| 51 | +your project. |
| 52 | + |
| 53 | +.. note:: |
| 54 | + |
| 55 | + If you have already added the {+driver-short+} as a dependency to your |
| 56 | + project, then you can skip this step. This is because the BSON library is already |
| 57 | + included as a required dependency of the driver. |
| 58 | + |
| 59 | +.. TODO: For instructions on how to add the |
| 60 | +.. MongoDB Kotlin driver as a dependency to your project, see the |
| 61 | +.. :ref:`driver installation <kotlin-sync-download-install>` section of our Get Started |
| 62 | +.. guide. |
| 63 | + |
| 64 | +We recommend that you use the `Maven <https://maven.apache.org/>`__ or |
| 65 | +`Gradle <https://gradle.org/>`__ build automation tool to manage your {+language+} |
| 66 | +project's dependencies. The following instructions detail the dependency declarations for |
| 67 | +both Maven and Gradle: |
| 68 | + |
| 69 | +.. tabs:: |
| 70 | + |
| 71 | + .. tab:: Maven |
| 72 | + :tabid: maven-dependencies |
| 73 | + |
| 74 | + The following snippet shows the dependency declaration in the |
| 75 | + ``dependencies`` section of your ``pom.xml`` file. |
| 76 | + |
| 77 | + .. include:: /includes/data-formats/bson-maven-versioned.rst |
| 78 | + |
| 79 | + .. tab:: Gradle |
| 80 | + :tabid: gradle-dependencies |
| 81 | + |
| 82 | + The following snippet shows the dependency declaration in the |
| 83 | + ``dependencies`` object in your ``build.gradle`` file. |
| 84 | + |
| 85 | + .. include:: /includes/data-formats/bson-gradle-versioned.rst |
| 86 | + |
| 87 | +If you are not using either of the preceding tools, then you can include the BSON dependency |
| 88 | +in your project by downloading the JAR file directly from the |
| 89 | +`sonatype repository <https://repo1.maven.org/maven2/org/mongodb/bson/>`__. |
0 commit comments