Skip to content

(DOCSP-39527): Consolidate Custom User Data page #3346

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 10 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
In this example, we use an Atlas Function to create the custom user data. The
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.

.. 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-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
@@ -0,0 +1,11 @@
In this example, we use an Atlas Function to delete the custom user data
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.

.. 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,6 @@
.. note::

If you require the most recent version of custom user data, use the
:cpp-sdk:`refresh_custom_user_data()
<structrealm_1_1user.html#a6e08623890de4003a00a351e939a0a9f>`
function to request the latest version of a user's custom data.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
To read the data, access the ``custom_data`` property on the ``User`` object
of a logged-in user.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
To update a user's custom user data with an Atlas Function, edit the
MongoDB document whose user ID field contains the user ID of the user.
The following example calls the same function used to create the custom user
data document above. Here, we update the ``favoriteColor`` field of the
the document containing the user ID of the currently logged in user.
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
@@ -0,0 +1,11 @@
This example uses an Atlas Function to create the custom user data document.
The Atlas 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.

.. literalinclude:: /examples/generated/flutter/writeCustomUserData.snippet.write-custom-user-data.js
:language: js
:caption: writeCustomUserData.js - Atlas Function running on server (JavaScript)

The client calls the Function to create the user data.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.. note::

If you require the most recent version of custom user data, use the
:flutter-sdk:`refreshCustomData() <realm/User/refreshCustomData.html>`
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,2 @@
To read custom user data, access the :flutter-sdk:`User.customData
<realm/User/customData.html>` property of a logged in user.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
This example uses an Atlas Function to update the custom user data document.
The Atlas 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.

.. literalinclude:: /examples/generated/flutter/writeCustomUserData.snippet.write-custom-user-data.js
:language: js
:caption: writeCustomUserData.js - Atlas Function running on server (JavaScript)

The client calls the Function to update the user data.
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 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
@@ -0,0 +1,6 @@
.. note::

If you require the most recent version of custom user data, use the
:java-sdk:`User.refreshCustomData()
<io/realm/mongodb/User.html#refreshCustomData()>`
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
:java-sdk:`User.getCustomData() <io/realm/mongodb/User.html#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 uses :ref:`MongoDB Data Access
<sdks-access-mongodb>` to update the ``favoriteColor`` field of
the document containing the user ID of the currently logged in user
in the custom user data collection.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.. note::

If you require the most recent version of custom user data, use the
:js-sdk:`User.refreshCustomData() <classes/User.html#refreshCustomData>`
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,2 @@
You retrieve custom user data in the :js-sdk:`customData <classes/User.html#customData>`
property of the ``User`` object.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This example uses :ref:`MongoDB remote access <sdks-access-mongodb>` to update
a user's custom data. The following example updates the custom data to alter
the user's ``favoriteColor`` to pink.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
This example calls an Atlas Function to create custom user data. In this
example, the Atlas Function takes an object passed by the client and
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.

.. literalinclude:: /examples/generated/kotlin/customUserData.snippet.write-custom-user-data.js
:language: js
:caption: writeCustomUserData.js - Atlas Function running on server (JavaScript)

The Kotlin SDK uses the following code to call this Function.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
This example calls an Atlas Function to delete custom user data.
In this example, 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.

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

The SDK 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,6 @@
.. note::

If you require the most recent version of custom user data, use the
:kotlin-sync-sdk:`User.refreshCustomData()
<io.realm.kotlin.mongodb/-user/refresh-custom-data.html>`
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,4 @@
You can read the custom user data of a currently logged-in user using the
:kotlin-sync-sdk:`User.customDataAsBsonDocument()
<io.realm.kotlin.mongodb.ext/custom-data-as-bson-document.html>`
extension function.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
This example calls an Atlas Function to update custom user data. In this
example, the Atlas Function takes an object passed by the client and
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.

.. literalinclude:: /examples/generated/kotlin/customUserData.snippet.write-custom-user-data.js
:language: js
:caption: writeCustomUserData.js - Atlas Function running on server (JavaScript)

The Kotlin SDK uses the following code to call this Function.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
The following example :ref:`accesses MongoDB <sdks-access-mongodb>` through
the ``MongoClient`` to insert document a into the custom user data collection.
This document contains the user ID of the currently logged in user and a
``favoriteColor`` value.
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, use the
:objc-sdk:`refreshCustomDataWithCompletion
<Classes/RLMUser.html#/c:objc(cs)RLMUser(im)refreshCustomDataWithCompletion:>`
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,2 @@
To read the data, access the ``customData`` property on the ``User`` object of
a logged-in user.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
To update a user's custom user data with MongoDB Data Access, edit the
MongoDB document whose user ID field contains the user ID of the user.
The following example uses :ref:`MongoDB Data Access <sdks-access-mongodb>` to
update the ``favoriteColor`` field of the the document containing the user ID
of the currently logged in user in the custom user data collection.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
The following example :ref:`accesses MongoDB <sdks-access-mongodb>` through
the ``MongoClient`` to insert document a into the custom user data collection.
This document contains the user ID of the currently logged in user and a
``favoriteColor`` value.
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, use the
:swift-sdk:`refreshCustomData()
<Extensions/User.html#/s:So7RLMUserC10RealmSwiftE17refreshCustomData7Combine6FutureCySDys11AnyHashableVypGs5Error_pGyF>`
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,2 @@
To read the data, access the ``customData`` property on the ``User`` object of
a logged-in user.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
To update a user's custom user data with MongoDB Data Access, edit the
MongoDB document whose user ID field contains the user ID of the user.
The following example uses :ref:`MongoDB Data Access <sdks-access-mongodb>` to
update the ``favoriteColor`` field of the the document containing the user ID
of the currently logged in user in the custom user data collection.
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
.. tabs-drivers::

tabs:
- id: cpp-sdk
content: |

.. literalinclude:: /examples/generated/cpp/custom-user-data.snippet.create.cpp
:language: cpp

- id: csharp
content: |

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

- id: dart
content: |

.. literalinclude:: /examples/generated/flutter/authenticate_users_test.snippet.write-custom-user-data-function.dart
:language: dart

- id: java
content: |

.. literalinclude:: /examples/generated/java/sync/AccessCustomUserDataTest.snippet.create-custom-user-data.java
:language: java
:emphasize-lines: 11,12

- id: java-kotlin
content: |

.. literalinclude:: /examples/generated/java/sync/AccessCustomUserDataTest.snippet.create-custom-user-data.kt
:language: kotlin
:emphasize-lines: 11

- id: javascript
content: |

.. literalinclude:: /examples/MissingPlaceholders/example.js
:language: javascript
:copyable: false

- id: kotlin
content: |

.. literalinclude:: /examples/generated/kotlin/AuthenticationTest.snippet.write-custom-user-data.kt
:language: kotlin

- id: objectivec
content: |

.. literalinclude:: /examples/generated/code/start/CustomUserData.snippet.create-custom-user-data.m
:language: objectivec

- id: swift
content: |

.. literalinclude:: /examples/generated/code/start/CustomUserData.snippet.create-custom-user-data.swift
:language: swift

- id: typescript
content: |

.. literalinclude:: /examples/MissingPlaceholders/example.ts
:language: typescript
:copyable: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
.. tabs-drivers::

tabs:
- id: cpp-sdk
content: |

.. literalinclude:: /examples/generated/cpp/custom-user-data.snippet.delete.cpp
:language: cpp

- id: csharp
content: |

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

- id: dart
content: |

.. literalinclude:: /examples/MissingPlaceholders/example.dart
:language: dart
:copyable: false

- id: java
content: |

.. literalinclude:: /examples/MissingPlaceholders/example.java
:language: java
:copyable: false

- id: java-kotlin
content: |

.. literalinclude:: /examples/MissingPlaceholders/example-java-kotlin.kt
:language: kotlin
:copyable: false

- id: javascript
content: |

.. literalinclude:: /examples/MissingPlaceholders/example.js
:language: javascript
:copyable: false

- id: kotlin
content: |

.. literalinclude:: /examples/generated/kotlin/AuthenticationTest.snippet.delete-custom-user-data.kt
:language: kotlin

- id: objectivec
content: |

.. literalinclude:: /examples/MissingPlaceholders/example.m
:language: objectivec
:copyable: false

- id: swift
content: |

.. literalinclude:: /examples/MissingPlaceholders/example.swift
:language: swift
:copyable: false

- id: typescript
content: |

.. literalinclude:: /examples/MissingPlaceholders/example.ts
:language: typescript
:copyable: false
Loading
Loading