Skip to content

Commit

Permalink
Add C# API descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
dacharyc committed Jul 30, 2024
1 parent fcba68e commit 68dbd41
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ Function takes an object passed by the client add adds it to the custom user
data collection in Atlas. The Function creates the custom user data if it
doesn't already exist and replaces all data in it if it does exist.

.. include:: /examples/generated/cpp/updateCustomUserData.snippet.update-custom-user-data.js
.. literalinclude:: /examples/generated/cpp/updateCustomUserData.snippet.update-custom-user-data.js
:language: js
:caption: updateCustomUserData.js - Atlas Function running on server (JavaScript)

The following example :ref:`calls a function <sdks-call-a-function>` to
The following example :ref:`calls a function <sdks-call-function>` to
insert a document containing the user ID of the currently logged in user
and a ``favoriteColor`` value into the custom user data collection.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ document. The Atlas Function does not require any arguments. The
Function uses the Function context to determine the caller's user ID, and
deletes the custom user data document matching the user's ID.

.. include:: /examples/generated/cpp/deleteCustomUserData.snippet.delete-custom-user-data.js
.. literalinclude:: /examples/generated/cpp/deleteCustomUserData.snippet.delete-custom-user-data.js
:language: js
:caption: deleteCustomUserData.js - Atlas Function running on server (JavaScript)

The code that calls this Function requires only a logged-in user to call
the Function.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
The following example uses
:ref:`MongoDB Data Access <sdks-access-mongodb>` to insert a
document containing the user ID of the currently logged in user and several
custom properties into the custom user data collection:

.. literalinclude:: /examples/generated/dotnet/CustomUserDataExamples.snippet.create.cs
:language: csharp

You may find it helpful to create a C# class (POCO) that represents the custom
user data object. The SDK will serialize/deserialize this class to and from BSON
when writing, reading, and updating properties. The example above uses the
following class to map the properties.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
The following example uses :ref:`MongoDB Data Access <sdks-access-mongodb>` to
find and deletes the data through the
:dotnet-sdk:`DeleteOneAsync() <reference/Realms.Sync.MongoClient.Collection-1.html#Realms_Sync_MongoClient_Collection_1_DeleteOneAsync_System_Object_>`
method.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.. note::

If you require the most recent version of custom user data, call the
:dotnet-sdk:`RefreshCustomDataAsync()
<reference/Realms.Sync.User.html#Realms_Sync_User_RefreshCustomDataAsync>`
method to request the latest version of a user's custom data.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
To read custom user data, call the
:dotnet-sdk:`GetCustomData() <reference/Realms.Sync.User.html#Realms_Sync_User_GetCustomData>`
method on the ``User`` object of a logged in user.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
The following example
finds and updates the data by using the
:dotnet-sdk:`UpdateOneAsync() <reference/Realms.Sync.MongoClient.Collection-1.html#Realms_Sync_MongoClient_Collection_1_UpdateOneAsync_System_Object_System_Object_System_Boolean_>`
method, and then refreshes the data to ensure the latest changes are available.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
- id: csharp
content: |

.. literalinclude:: /examples/MissingPlaceholders/example.cs
.. literalinclude:: /examples/generated/dotnet/CustomUserDataExamples.snippet.cud.cs
:language: csharp

- id: dart
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
- id: csharp
content: |

.. literalinclude:: /examples/MissingPlaceholders/example.cs
.. literalinclude:: /examples/generated/dotnet/CustomUserDataExamples.snippet.delete.cs
:language: csharp
:copyable: false

- id: dart
content: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
- id: csharp
content: |

.. literalinclude:: /examples/MissingPlaceholders/example.cs
.. literalinclude:: /examples/generated/dotnet/CustomUserDataExamples.snippet.read.cs
:language: csharp

- id: dart
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
- id: csharp
content: |

.. literalinclude:: /examples/MissingPlaceholders/example.cs
.. literalinclude:: /examples/generated/dotnet/CustomUserDataExamples.snippet.update.cs
:language: csharp

- id: dart
Expand Down
16 changes: 9 additions & 7 deletions source/sdk/users/custom-user-data.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ ways:
.. tab::
:tabid: csharp

.. include:: /includes/api-details/generic/crud/create-asymmetric-object-description.rst
.. include:: /includes/api-details/csharp/users/custom-user-data-create-custom-user-data-description.rst

.. tab::
:tabid: dart

Expand Down Expand Up @@ -158,8 +158,8 @@ data, see the Update Custom User Data section on this page.
.. tab::
:tabid: csharp

.. include:: /includes/api-details/generic/crud/create-asymmetric-object-description.rst
.. include:: /includes/api-details/csharp/users/custom-user-data-read-custom-user-data-description.rst

.. tab::
:tabid: dart

Expand Down Expand Up @@ -224,7 +224,7 @@ data, see the Update Custom User Data section on this page.
.. tab::
:tabid: csharp

.. include:: /includes/api-details/generic/crud/create-asymmetric-object-description.rst
.. include:: /includes/api-details/csharp/users/custom-user-data-read-custom-user-data-2-description.rst

.. tab::
:tabid: dart
Expand Down Expand Up @@ -291,7 +291,7 @@ You can update custom user data in a few ways:
.. tab::
:tabid: csharp

.. include:: /includes/api-details/generic/crud/create-asymmetric-object-description.rst
.. include:: /includes/api-details/csharp/users/custom-user-data-update-custom-user-data-description.rst

.. tab::
:tabid: dart
Expand Down Expand Up @@ -365,7 +365,9 @@ You can delete custom user data in a few ways:

.. tab::
:tabid: csharp


.. include:: /includes/api-details/csharp/users/custom-user-data-delete-custom-user-data-description.rst

.. tab::
:tabid: dart

Expand Down

0 comments on commit 68dbd41

Please sign in to comment.