Skip to content

DOCSP-49876: Add IBsonReader and IBsonWriter info #641

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
May 30, 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
24 changes: 23 additions & 1 deletion source/data-formats/bson.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ BSON Operations

.. default-domain:: mongodb

.. meta::
:keywords: document, BSON, serializer

.. contents:: On this page
:local:
:backlinks: none
Expand Down Expand Up @@ -44,7 +47,8 @@ The code samples in this guide use the following BSON document as an example:
Create a BSON Document
----------------------

To build a BSON document in {+language+}, create an instance of the ``BsonDocument`` class.
To build a representation of a BSON document in {+language+}, create an instance of the
``BsonDocument`` class.
The ``BsonDocument`` constructor accepts ``BsonElement`` arguments that map to the fields
and values in the document. Each ``BsonElement`` can be either an instance of the
``BsonElement`` class or a field-value pair inside curly braces ( ``{}`` ).
Expand Down Expand Up @@ -212,6 +216,22 @@ BSON document stored in ``myFile.bson``:
``System.IO.Stream`` object. This means that you can read or write any location
that can be accessed by a stream.

Read and Write Other Formats
----------------------------

The preceding examples show how to read and write BSON data by using the
``BsonBinaryReader`` and ``BsonBinaryWriter`` classes. These classes implement the
``IBsonReader`` and ``IBsonWriter`` interfaces. To read and write data in other formats,
the {+driver-short+} provides the following alternative implementations of the ``IBsonReader``
and ``IBsonWriter`` interfaces:

- ``JsonReader`` and ``JsonWriter``: Read and write JSON data
- ``BsonDocumentReader`` and ``BsonDocumentWriter``: Read and write BSON data
contained in a ``BsonDocument`` object

Because these classes implement the same interfaces, you can call their methods in the same way
as the preceding ``BsonBinaryReader`` and ``BsonBinaryWriter`` examples.

.. _csharp-bson-api:

API Documentation
Expand All @@ -224,3 +244,5 @@ guide, see the following API documentation:
- `BsonElement <{+new-api-root+}/MongoDB.Bson/MongoDB.Bson.BsonElement.html>`__
- `BsonBinaryReader <{+new-api-root+}/MongoDB.Bson/MongoDB.Bson.IO.BsonBinaryReader.html>`__
- `BsonBinaryWriter <{+new-api-root+}/MongoDB.Bson/MongoDB.Bson.IO.BsonBinaryWriter.html>`__
- `IBsonReader <{+new-api-root+}/MongoDB.Bson/MongoDB.Bson.IO.IBsonReader.html>`__
- `IBsonWriter <{+new-api-root+}/MongoDB.Bson/MongoDB.Bson.IO.IBsonWriter.html>`__
Loading