diff --git a/source/includes/api-details/cpp/users/custom-user-data-create-custom-user-data-description.rst b/source/includes/api-details/cpp/users/custom-user-data-create-custom-user-data-description.rst new file mode 100644 index 0000000000..33e3772fa8 --- /dev/null +++ b/source/includes/api-details/cpp/users/custom-user-data-create-custom-user-data-description.rst @@ -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 ` to +insert a document containing the user ID of the currently logged in user +and a ``favoriteColor`` value into the custom user data collection. diff --git a/source/includes/api-details/cpp/users/custom-user-data-delete-custom-user-data-description.rst b/source/includes/api-details/cpp/users/custom-user-data-delete-custom-user-data-description.rst new file mode 100644 index 0000000000..c2d40f1187 --- /dev/null +++ b/source/includes/api-details/cpp/users/custom-user-data-delete-custom-user-data-description.rst @@ -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. diff --git a/source/includes/api-details/cpp/users/custom-user-data-read-custom-user-data-2-description.rst b/source/includes/api-details/cpp/users/custom-user-data-read-custom-user-data-2-description.rst new file mode 100644 index 0000000000..668dca5e3c --- /dev/null +++ b/source/includes/api-details/cpp/users/custom-user-data-read-custom-user-data-2-description.rst @@ -0,0 +1,6 @@ +.. note:: + + If you require the most recent version of custom user data, use the + :cpp-sdk:`refresh_custom_user_data() + ` + function to request the latest version of a user's custom data. diff --git a/source/includes/api-details/cpp/users/custom-user-data-read-custom-user-data-description.rst b/source/includes/api-details/cpp/users/custom-user-data-read-custom-user-data-description.rst new file mode 100644 index 0000000000..c64b179ec6 --- /dev/null +++ b/source/includes/api-details/cpp/users/custom-user-data-read-custom-user-data-description.rst @@ -0,0 +1,2 @@ +To read the data, access the ``custom_data`` property on the ``User`` object +of a logged-in user. diff --git a/source/includes/api-details/cpp/users/custom-user-data-update-custom-user-data-description.rst b/source/includes/api-details/cpp/users/custom-user-data-update-custom-user-data-description.rst new file mode 100644 index 0000000000..3f61d18321 --- /dev/null +++ b/source/includes/api-details/cpp/users/custom-user-data-update-custom-user-data-description.rst @@ -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. diff --git a/source/includes/api-details/csharp/users/custom-user-data-create-custom-user-data-description.rst b/source/includes/api-details/csharp/users/custom-user-data-create-custom-user-data-description.rst new file mode 100644 index 0000000000..7e146d351a --- /dev/null +++ b/source/includes/api-details/csharp/users/custom-user-data-create-custom-user-data-description.rst @@ -0,0 +1,12 @@ +The following example uses +:ref:`MongoDB Data Access ` 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. diff --git a/source/includes/api-details/csharp/users/custom-user-data-delete-custom-user-data-description.rst b/source/includes/api-details/csharp/users/custom-user-data-delete-custom-user-data-description.rst new file mode 100644 index 0000000000..129e0683ac --- /dev/null +++ b/source/includes/api-details/csharp/users/custom-user-data-delete-custom-user-data-description.rst @@ -0,0 +1,4 @@ +The following example uses :ref:`MongoDB Data Access ` to +find and deletes the data through the +:dotnet-sdk:`DeleteOneAsync() ` +method. diff --git a/source/includes/api-details/csharp/users/custom-user-data-read-custom-user-data-2-description.rst b/source/includes/api-details/csharp/users/custom-user-data-read-custom-user-data-2-description.rst new file mode 100644 index 0000000000..ad896b4c36 --- /dev/null +++ b/source/includes/api-details/csharp/users/custom-user-data-read-custom-user-data-2-description.rst @@ -0,0 +1,6 @@ +.. note:: + + If you require the most recent version of custom user data, call the + :dotnet-sdk:`RefreshCustomDataAsync() + ` + method to request the latest version of a user's custom data. diff --git a/source/includes/api-details/csharp/users/custom-user-data-read-custom-user-data-description.rst b/source/includes/api-details/csharp/users/custom-user-data-read-custom-user-data-description.rst new file mode 100644 index 0000000000..37b0485508 --- /dev/null +++ b/source/includes/api-details/csharp/users/custom-user-data-read-custom-user-data-description.rst @@ -0,0 +1,3 @@ +To read custom user data, call the +:dotnet-sdk:`GetCustomData() ` +method on the ``User`` object of a logged in user. diff --git a/source/includes/api-details/csharp/users/custom-user-data-update-custom-user-data-description.rst b/source/includes/api-details/csharp/users/custom-user-data-update-custom-user-data-description.rst new file mode 100644 index 0000000000..af7f2d2892 --- /dev/null +++ b/source/includes/api-details/csharp/users/custom-user-data-update-custom-user-data-description.rst @@ -0,0 +1,4 @@ +The following example +finds and updates the data by using the +:dotnet-sdk:`UpdateOneAsync() ` +method, and then refreshes the data to ensure the latest changes are available. diff --git a/source/includes/api-details/dart/users/custom-user-data-create-custom-user-data-description.rst b/source/includes/api-details/dart/users/custom-user-data-create-custom-user-data-description.rst new file mode 100644 index 0000000000..72b4f9b64e --- /dev/null +++ b/source/includes/api-details/dart/users/custom-user-data-create-custom-user-data-description.rst @@ -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. diff --git a/source/includes/api-details/dart/users/custom-user-data-read-custom-user-data-2-description.rst b/source/includes/api-details/dart/users/custom-user-data-read-custom-user-data-2-description.rst new file mode 100644 index 0000000000..71ae01fc98 --- /dev/null +++ b/source/includes/api-details/dart/users/custom-user-data-read-custom-user-data-2-description.rst @@ -0,0 +1,5 @@ +.. note:: + + If you require the most recent version of custom user data, use the + :flutter-sdk:`refreshCustomData() ` + method to request the latest version of a user's custom data. diff --git a/source/includes/api-details/dart/users/custom-user-data-read-custom-user-data-description.rst b/source/includes/api-details/dart/users/custom-user-data-read-custom-user-data-description.rst new file mode 100644 index 0000000000..5d4c476b27 --- /dev/null +++ b/source/includes/api-details/dart/users/custom-user-data-read-custom-user-data-description.rst @@ -0,0 +1,2 @@ +To read custom user data, access the :flutter-sdk:`User.customData +` property of a logged in user. diff --git a/source/includes/api-details/dart/users/custom-user-data-update-custom-user-data-description.rst b/source/includes/api-details/dart/users/custom-user-data-update-custom-user-data-description.rst new file mode 100644 index 0000000000..0066a0819b --- /dev/null +++ b/source/includes/api-details/dart/users/custom-user-data-update-custom-user-data-description.rst @@ -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. diff --git a/source/includes/api-details/java/users/custom-user-data-create-custom-user-data-description.rst b/source/includes/api-details/java/users/custom-user-data-create-custom-user-data-description.rst new file mode 100644 index 0000000000..c219f56536 --- /dev/null +++ b/source/includes/api-details/java/users/custom-user-data-create-custom-user-data-description.rst @@ -0,0 +1,4 @@ +The following example uses +:ref:`MongoDB Data Access ` to insert a +document containing the user ID of the currently logged in user and a +``favoriteColor`` value into the custom user data collection. diff --git a/source/includes/api-details/java/users/custom-user-data-read-custom-user-data-2-description.rst b/source/includes/api-details/java/users/custom-user-data-read-custom-user-data-2-description.rst new file mode 100644 index 0000000000..fc67410091 --- /dev/null +++ b/source/includes/api-details/java/users/custom-user-data-read-custom-user-data-2-description.rst @@ -0,0 +1,6 @@ +.. note:: + + If you require the most recent version of custom user data, use the + :java-sdk:`User.refreshCustomData() + ` + method to request the latest version of a user's custom data. diff --git a/source/includes/api-details/java/users/custom-user-data-read-custom-user-data-description.rst b/source/includes/api-details/java/users/custom-user-data-read-custom-user-data-description.rst new file mode 100644 index 0000000000..68469af4d7 --- /dev/null +++ b/source/includes/api-details/java/users/custom-user-data-read-custom-user-data-description.rst @@ -0,0 +1,3 @@ +To read custom user data, call the +:java-sdk:`User.getCustomData() ` +method on the ``User`` object of a logged in user. diff --git a/source/includes/api-details/java/users/custom-user-data-update-custom-user-data-description.rst b/source/includes/api-details/java/users/custom-user-data-update-custom-user-data-description.rst new file mode 100644 index 0000000000..2a1f3bf9b9 --- /dev/null +++ b/source/includes/api-details/java/users/custom-user-data-update-custom-user-data-description.rst @@ -0,0 +1,4 @@ +The following example uses :ref:`MongoDB Data Access +` to update the ``favoriteColor`` field of +the document containing the user ID of the currently logged in user +in the custom user data collection. diff --git a/source/includes/api-details/javascript/users/custom-user-data-read-custom-user-data-js-ts-2-description.rst b/source/includes/api-details/javascript/users/custom-user-data-read-custom-user-data-js-ts-2-description.rst new file mode 100644 index 0000000000..6bfad6375e --- /dev/null +++ b/source/includes/api-details/javascript/users/custom-user-data-read-custom-user-data-js-ts-2-description.rst @@ -0,0 +1,5 @@ +.. note:: + + If you require the most recent version of custom user data, use the + :js-sdk:`User.refreshCustomData() ` + method to request the latest version of a user's custom data. diff --git a/source/includes/api-details/javascript/users/custom-user-data-read-custom-user-data-js-ts-description.rst b/source/includes/api-details/javascript/users/custom-user-data-read-custom-user-data-js-ts-description.rst new file mode 100644 index 0000000000..0fcb48a001 --- /dev/null +++ b/source/includes/api-details/javascript/users/custom-user-data-read-custom-user-data-js-ts-description.rst @@ -0,0 +1,2 @@ +You retrieve custom user data in the :js-sdk:`customData ` +property of the ``User`` object. diff --git a/source/includes/api-details/javascript/users/custom-user-data-update-custom-user-data-description.rst b/source/includes/api-details/javascript/users/custom-user-data-update-custom-user-data-description.rst new file mode 100644 index 0000000000..37e09e3e7c --- /dev/null +++ b/source/includes/api-details/javascript/users/custom-user-data-update-custom-user-data-description.rst @@ -0,0 +1,3 @@ +This example uses :ref:`MongoDB remote access ` to update +a user's custom data. The following example updates the custom data to alter +the user's ``favoriteColor`` to pink. diff --git a/source/includes/api-details/kotlin/users/custom-user-data-create-custom-user-data-description.rst b/source/includes/api-details/kotlin/users/custom-user-data-create-custom-user-data-description.rst new file mode 100644 index 0000000000..5165fcb7c6 --- /dev/null +++ b/source/includes/api-details/kotlin/users/custom-user-data-create-custom-user-data-description.rst @@ -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. diff --git a/source/includes/api-details/kotlin/users/custom-user-data-delete-custom-user-data-description.rst b/source/includes/api-details/kotlin/users/custom-user-data-delete-custom-user-data-description.rst new file mode 100644 index 0000000000..19165e7c1c --- /dev/null +++ b/source/includes/api-details/kotlin/users/custom-user-data-delete-custom-user-data-description.rst @@ -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. diff --git a/source/includes/api-details/kotlin/users/custom-user-data-read-custom-user-data-2-description.rst b/source/includes/api-details/kotlin/users/custom-user-data-read-custom-user-data-2-description.rst new file mode 100644 index 0000000000..687e929221 --- /dev/null +++ b/source/includes/api-details/kotlin/users/custom-user-data-read-custom-user-data-2-description.rst @@ -0,0 +1,6 @@ +.. note:: + + If you require the most recent version of custom user data, use the + :kotlin-sync-sdk:`User.refreshCustomData() + ` + method to request the latest version of a user's custom data. diff --git a/source/includes/api-details/kotlin/users/custom-user-data-read-custom-user-data-description.rst b/source/includes/api-details/kotlin/users/custom-user-data-read-custom-user-data-description.rst new file mode 100644 index 0000000000..06946f5c98 --- /dev/null +++ b/source/includes/api-details/kotlin/users/custom-user-data-read-custom-user-data-description.rst @@ -0,0 +1,4 @@ +You can read the custom user data of a currently logged-in user using the +:kotlin-sync-sdk:`User.customDataAsBsonDocument() +` +extension function. diff --git a/source/includes/api-details/kotlin/users/custom-user-data-update-custom-user-data-description.rst b/source/includes/api-details/kotlin/users/custom-user-data-update-custom-user-data-description.rst new file mode 100644 index 0000000000..81bd367c2c --- /dev/null +++ b/source/includes/api-details/kotlin/users/custom-user-data-update-custom-user-data-description.rst @@ -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. diff --git a/source/includes/api-details/objectivec/users/custom-user-data-create-custom-user-data-description.rst b/source/includes/api-details/objectivec/users/custom-user-data-create-custom-user-data-description.rst new file mode 100644 index 0000000000..a8a2dddb3f --- /dev/null +++ b/source/includes/api-details/objectivec/users/custom-user-data-create-custom-user-data-description.rst @@ -0,0 +1,4 @@ +The following example :ref:`accesses 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. diff --git a/source/includes/api-details/objectivec/users/custom-user-data-read-custom-user-data-2-description.rst b/source/includes/api-details/objectivec/users/custom-user-data-read-custom-user-data-2-description.rst new file mode 100644 index 0000000000..d3034e7b21 --- /dev/null +++ b/source/includes/api-details/objectivec/users/custom-user-data-read-custom-user-data-2-description.rst @@ -0,0 +1,6 @@ +.. note:: + + If you require the most recent version of custom user data, use the + :objc-sdk:`refreshCustomDataWithCompletion + ` + method to request the latest version of a user's custom data. diff --git a/source/includes/api-details/objectivec/users/custom-user-data-read-custom-user-data-description.rst b/source/includes/api-details/objectivec/users/custom-user-data-read-custom-user-data-description.rst new file mode 100644 index 0000000000..355038dc59 --- /dev/null +++ b/source/includes/api-details/objectivec/users/custom-user-data-read-custom-user-data-description.rst @@ -0,0 +1,2 @@ +To read the data, access the ``customData`` property on the ``User`` object of +a logged-in user. diff --git a/source/includes/api-details/objectivec/users/custom-user-data-update-custom-user-data-description.rst b/source/includes/api-details/objectivec/users/custom-user-data-update-custom-user-data-description.rst new file mode 100644 index 0000000000..344c2b9eb0 --- /dev/null +++ b/source/includes/api-details/objectivec/users/custom-user-data-update-custom-user-data-description.rst @@ -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 ` 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. diff --git a/source/includes/api-details/swift/users/custom-user-data-create-custom-user-data-description.rst b/source/includes/api-details/swift/users/custom-user-data-create-custom-user-data-description.rst new file mode 100644 index 0000000000..a8a2dddb3f --- /dev/null +++ b/source/includes/api-details/swift/users/custom-user-data-create-custom-user-data-description.rst @@ -0,0 +1,4 @@ +The following example :ref:`accesses 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. diff --git a/source/includes/api-details/swift/users/custom-user-data-read-custom-user-data-2-description.rst b/source/includes/api-details/swift/users/custom-user-data-read-custom-user-data-2-description.rst new file mode 100644 index 0000000000..1dc3ab652c --- /dev/null +++ b/source/includes/api-details/swift/users/custom-user-data-read-custom-user-data-2-description.rst @@ -0,0 +1,6 @@ +.. note:: + + If you require the most recent version of custom user data, use the + :swift-sdk:`refreshCustomData() + ` + method to request the latest version of a user's custom data. diff --git a/source/includes/api-details/swift/users/custom-user-data-read-custom-user-data-description.rst b/source/includes/api-details/swift/users/custom-user-data-read-custom-user-data-description.rst new file mode 100644 index 0000000000..355038dc59 --- /dev/null +++ b/source/includes/api-details/swift/users/custom-user-data-read-custom-user-data-description.rst @@ -0,0 +1,2 @@ +To read the data, access the ``customData`` property on the ``User`` object of +a logged-in user. diff --git a/source/includes/api-details/swift/users/custom-user-data-update-custom-user-data-description.rst b/source/includes/api-details/swift/users/custom-user-data-update-custom-user-data-description.rst new file mode 100644 index 0000000000..344c2b9eb0 --- /dev/null +++ b/source/includes/api-details/swift/users/custom-user-data-update-custom-user-data-description.rst @@ -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 ` 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. diff --git a/source/includes/sdk-examples/users/custom-user-data-create-custom-user-data.rst b/source/includes/sdk-examples/users/custom-user-data-create-custom-user-data.rst new file mode 100644 index 0000000000..f25d297e6d --- /dev/null +++ b/source/includes/sdk-examples/users/custom-user-data-create-custom-user-data.rst @@ -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 diff --git a/source/includes/sdk-examples/users/custom-user-data-delete-custom-user-data.rst b/source/includes/sdk-examples/users/custom-user-data-delete-custom-user-data.rst new file mode 100644 index 0000000000..b8bb129bf5 --- /dev/null +++ b/source/includes/sdk-examples/users/custom-user-data-delete-custom-user-data.rst @@ -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 diff --git a/source/includes/sdk-examples/users/custom-user-data-read-custom-user-data.rst b/source/includes/sdk-examples/users/custom-user-data-read-custom-user-data.rst new file mode 100644 index 0000000000..7a4314eeaf --- /dev/null +++ b/source/includes/sdk-examples/users/custom-user-data-read-custom-user-data.rst @@ -0,0 +1,65 @@ +.. tabs-drivers:: + + tabs: + - id: cpp-sdk + content: | + + .. literalinclude:: /examples/generated/cpp/custom-user-data.snippet.read.cpp + :language: cpp + + - id: csharp + content: | + + .. literalinclude:: /examples/generated/dotnet/CustomUserDataExamples.snippet.read.cs + :language: csharp + + - id: dart + content: | + + .. literalinclude:: /examples/generated/flutter/authenticate_users_test.snippet.read-custom-user-data.dart + :language: dart + + - id: java + content: | + + .. literalinclude:: /examples/generated/java/sync/AccessCustomUserDataTest.snippet.read-custom-user-data.java + :language: java + :emphasize-lines: 6 + + - id: java-kotlin + content: | + + .. literalinclude:: /examples/generated/java/sync/AccessCustomUserDataTest.snippet.read-custom-user-data.kt + :language: kotlin + :emphasize-lines: 6 + + - id: javascript + content: | + + .. literalinclude:: /examples/generated/node/custom-user-data.snippet.read-custom-user-data.js + :language: javascript + + - id: kotlin + content: | + + .. literalinclude:: /examples/generated/kotlin/AuthenticationTest.snippet.read-custom-user-data.kt + :language: kotlin + + - id: objectivec + content: | + + .. literalinclude:: /examples/generated/code/start/CustomUserData.snippet.read-custom-user-data.m + :language: objectivec + + - id: swift + content: | + + .. literalinclude:: /examples/generated/code/start/CustomUserData.snippet.read-custom-user-data.swift + :language: swift + + - id: typescript + content: | + + .. literalinclude:: /examples/MissingPlaceholders/example.ts + :language: typescript + :copyable: false diff --git a/source/includes/sdk-examples/users/custom-user-data-update-custom-user-data.rst b/source/includes/sdk-examples/users/custom-user-data-update-custom-user-data.rst new file mode 100644 index 0000000000..762ac38742 --- /dev/null +++ b/source/includes/sdk-examples/users/custom-user-data-update-custom-user-data.rst @@ -0,0 +1,65 @@ +.. tabs-drivers:: + + tabs: + - id: cpp-sdk + content: | + + .. literalinclude:: /examples/generated/cpp/custom-user-data.snippet.update.cpp + :language: cpp + + - id: csharp + content: | + + .. literalinclude:: /examples/generated/dotnet/CustomUserDataExamples.snippet.update.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.update-custom-user-data.java + :language: java + :emphasize-lines: 11,12 + + - id: java-kotlin + content: | + + .. literalinclude:: /examples/generated/java/sync/AccessCustomUserDataTest.snippet.update-custom-user-data.kt + :language: kotlin + :emphasize-lines: 11 + + - id: javascript + content: | + + .. literalinclude:: /examples/generated/node/custom-user-data.snippet.write-custom-user-data.js + :language: javascript + + - 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.update-custom-user-data.m + :language: objectivec + + - id: swift + content: | + + .. literalinclude:: /examples/generated/code/start/CustomUserData.snippet.update-custom-user-data.swift + :language: swift + + - id: typescript + content: | + + .. literalinclude:: /examples/MissingPlaceholders/example.ts + :language: typescript + :copyable: false diff --git a/source/sdk/users/custom-user-data.txt b/source/sdk/users/custom-user-data.txt index f2bf49e077..2983160c63 100644 --- a/source/sdk/users/custom-user-data.txt +++ b/source/sdk/users/custom-user-data.txt @@ -4,10 +4,400 @@ Custom User Data ================ +.. meta:: + :description: Learn how to store and access custom user data using Atlas Device SDK. + :keywords: Realm, C++ SDK, Flutter SDK, Kotlin SDK, Java SDK, .NET SDK, Node.js SDK, Swift SDK, code example + +.. facet:: + :name: genre + :values: tutorial + +.. facet:: + :name: programming_language + :values: cpp, csharp, dart, java, javascript/typescript, kotlin, objective-c, swift + .. contents:: On this page :local: :backlinks: none :depth: 2 :class: singlecol -Placeholder page for information about custom user data. +.. tabs-selector:: drivers + +This page describes custom user data in an App Services App and how to manage it +with Atlas Device SDK. + +Atlas App Services lets you associate data with an authenticated user, such as +a user's preferred language, date of birth, or local timezone. You can store +this arbitrary **custom user data** about your users and read it from your +client application. + +Prerequisites +------------- + +To use custom user data, you must have an App Services App with custom user +data enabled. + +To set up an App Services App that uses custom user data, refer to the +following: + +#. :ref:`Enable Custom User Data ` + in the App Services documentation +#. :ref:`sdks-connect-to-atlas` + +.. _sdks-create-custom-user-data: + +Create Custom User Data +----------------------- + +When you configure custom user data in Atlas, you designate a database and +collection to store the custom user data. This data is stored as documents in +Atlas. + +To create custom user data for a user, create a MongoDB document in the +custom user data collection. The user ID field of the document should +contain the user's user ID. You can create custom user data documents in a few +ways: + +- Define a User Creation Function that automatically creates custom user data + as part of the user registration process. +- Define a Function that you call with the user data, perhaps sometime + after registration. +- Access MongoDB through the SDK, if your language supports it, and insert a + document directly into the custom user data collection. +- Manually create a custom data document through: + + - :compass:`MongoDB Compass ` + - :atlas:`MongoDB Atlas Data Explorer ` + +.. tip:: + + In the App Services UI, check the :guilabel:`App Users` page under the + :guilabel:`Custom User Data` tab to find and configure custom user + data settings, including: + + - The custom user data cluster, database, and collection + - The user ID field used to map custom user data documents to users + +.. tabs-drivers:: + + .. tab:: + :tabid: cpp-sdk + + .. include:: /includes/api-details/cpp/users/custom-user-data-create-custom-user-data-description.rst + + .. tab:: + :tabid: csharp + + .. include:: /includes/api-details/csharp/users/custom-user-data-create-custom-user-data-description.rst + + .. tab:: + :tabid: dart + + .. include:: /includes/api-details/dart/users/custom-user-data-create-custom-user-data-description.rst + + .. tab:: + :tabid: java + + .. include:: /includes/api-details/java/users/custom-user-data-create-custom-user-data-description.rst + + .. tab:: + :tabid: java-kotlin + + .. include:: /includes/api-details/java/users/custom-user-data-create-custom-user-data-description.rst + + .. tab:: + :tabid: javascript + + + + .. tab:: + :tabid: kotlin + + .. include:: /includes/api-details/kotlin/users/custom-user-data-create-custom-user-data-description.rst + + .. tab:: + :tabid: objectivec + + .. include:: /includes/api-details/objectivec/users/custom-user-data-create-custom-user-data-description.rst + + .. tab:: + :tabid: swift + + .. include:: /includes/api-details/swift/users/custom-user-data-create-custom-user-data-description.rst + + .. tab:: + :tabid: typescript + + + +.. include:: /includes/sdk-examples/users/custom-user-data-create-custom-user-data.rst + +You can add any number of arbitrary fields and values to the custom user +data document when you create it. The user ID field is the only +requirement for the document to become available on the ``User`` object +as custom user data. + +.. _sdks-read-custom-user-data: + +Read Custom User Data +--------------------- + +You can read the :ref:`custom user data ` of a +currently logged-in user through that user's ``User`` object. You cannot +edit custom user data through a ``User`` object. To edit custom user +data, see the Update Custom User Data section on this page. + +.. tabs-drivers:: + + .. tab:: + :tabid: cpp-sdk + + .. include:: /includes/api-details/cpp/users/custom-user-data-read-custom-user-data-description.rst + + .. tab:: + :tabid: csharp + + .. include:: /includes/api-details/csharp/users/custom-user-data-read-custom-user-data-description.rst + + .. tab:: + :tabid: dart + + .. include:: /includes/api-details/dart/users/custom-user-data-read-custom-user-data-description.rst + + .. tab:: + :tabid: java + + .. include:: /includes/api-details/java/users/custom-user-data-read-custom-user-data-description.rst + + .. tab:: + :tabid: java-kotlin + + .. include:: /includes/api-details/java/users/custom-user-data-read-custom-user-data-description.rst + + .. tab:: + :tabid: javascript + + .. include:: /includes/api-details/javascript/users/custom-user-data-read-custom-user-data-js-ts-description.rst + + .. tab:: + :tabid: kotlin + + .. include:: /includes/api-details/kotlin/users/custom-user-data-read-custom-user-data-description.rst + + .. tab:: + :tabid: objectivec + + .. include:: /includes/api-details/objectivec/users/custom-user-data-read-custom-user-data-description.rst + + .. tab:: + :tabid: swift + + .. include:: /includes/api-details/swift/users/custom-user-data-read-custom-user-data-description.rst + + .. tab:: + :tabid: typescript + + .. include:: /includes/api-details/javascript/users/custom-user-data-read-custom-user-data-js-ts-description.rst + +.. include:: /includes/sdk-examples/users/custom-user-data-read-custom-user-data.rst + +.. warning:: Custom Data May Be Stale + + Atlas App Services does not dynamically update the value of the client-side + user custom data document immediately when underlying data changes. + Instead, App Services fetches the most recent version of custom user + data whenever a user refreshes their :ref:`access token + `, which is used by most SDK operations that contact + the App Services backend. If the token is not refreshed before its default + 30 minute expiration time, the SDK refreshes the token on the next call to + the backend. Custom user data could be stale for up to 30 minutes plus the + time until the next SDK call to the backend occurs. + +.. tabs-drivers:: + + .. tab:: + :tabid: cpp-sdk + + .. include:: /includes/api-details/cpp/users/custom-user-data-read-custom-user-data-2-description.rst + + .. tab:: + :tabid: csharp + + .. include:: /includes/api-details/csharp/users/custom-user-data-read-custom-user-data-2-description.rst + + .. tab:: + :tabid: dart + + .. include:: /includes/api-details/dart/users/custom-user-data-read-custom-user-data-2-description.rst + + .. tab:: + :tabid: java + + .. include:: /includes/api-details/java/users/custom-user-data-read-custom-user-data-2-description.rst + + .. tab:: + :tabid: java-kotlin + + .. include:: /includes/api-details/java/users/custom-user-data-read-custom-user-data-2-description.rst + + .. tab:: + :tabid: javascript + + .. include:: /includes/api-details/javascript/users/custom-user-data-read-custom-user-data-js-ts-2-description.rst + + .. tab:: + :tabid: kotlin + + .. include:: /includes/api-details/kotlin/users/custom-user-data-read-custom-user-data-2-description.rst + + .. tab:: + :tabid: objectivec + + .. include:: /includes/api-details/objectivec/users/custom-user-data-read-custom-user-data-2-description.rst + + .. tab:: + :tabid: swift + + .. include:: /includes/api-details/swift/users/custom-user-data-read-custom-user-data-2-description.rst + + .. tab:: + :tabid: typescript + + .. include:: /includes/api-details/javascript/users/custom-user-data-read-custom-user-data-js-ts-2-description.rst + +.. _sdks-update-custom-user-data: + +Update Custom User Data +----------------------- + +You can update custom user data in a few ways: + +- Define a Function that you call with the updated user data. +- Access MongoDB through the SDK, if your language supports it, and update + the user data document in the custom user data collection directly. +- Manually update a custom data document through: + + - :compass:`MongoDB Compass ` + - :atlas:`MongoDB Atlas Data Explorer ` + +.. tabs-drivers:: + + .. tab:: + :tabid: cpp-sdk + + .. include:: /includes/api-details/cpp/users/custom-user-data-update-custom-user-data-description.rst + + .. tab:: + :tabid: csharp + + .. include:: /includes/api-details/csharp/users/custom-user-data-update-custom-user-data-description.rst + + .. tab:: + :tabid: dart + + .. include:: /includes/api-details/dart/users/custom-user-data-update-custom-user-data-description.rst + + .. tab:: + :tabid: java + + .. include:: /includes/api-details/java/users/custom-user-data-update-custom-user-data-description.rst + + .. tab:: + :tabid: java-kotlin + + .. include:: /includes/api-details/java/users/custom-user-data-update-custom-user-data-description.rst + + .. tab:: + :tabid: javascript + + .. include:: /includes/api-details/javascript/users/custom-user-data-update-custom-user-data-description.rst + + .. tab:: + :tabid: kotlin + + .. include:: /includes/api-details/kotlin/users/custom-user-data-update-custom-user-data-description.rst + + .. tab:: + :tabid: objectivec + + .. include:: /includes/api-details/objectivec/users/custom-user-data-update-custom-user-data-description.rst + + .. tab:: + :tabid: swift + + .. include:: /includes/api-details/swift/users/custom-user-data-update-custom-user-data-description.rst + + .. tab:: + :tabid: typescript + + + +.. include:: /includes/sdk-examples/users/custom-user-data-update-custom-user-data.rst + +.. _sdks-delete-custom-user-data: + +Delete Custom User Data +----------------------- + +Custom user data is stored in a document linked to the user object. +Deleting a user does not delete the custom user data. To fully delete user +data to comply with, for example, :apple:`Apple's Account deletion guidance +`, you must manually delete +the user's custom data document. + +You can delete custom user data in a few ways: + +- Define a Function that you call to delete custom user data. +- Access MongoDB through the SDK, if your language supports it, and delete + the user data document from the custom user data collection directly. +- Manually delete a custom data document through: + + - :compass:`MongoDB Compass ` + - :atlas:`MongoDB Atlas Data Explorer ` + +.. tabs-drivers:: + + .. tab:: + :tabid: cpp-sdk + + .. include:: /includes/api-details/cpp/users/custom-user-data-delete-custom-user-data-description.rst + + .. tab:: + :tabid: csharp + + .. include:: /includes/api-details/csharp/users/custom-user-data-delete-custom-user-data-description.rst + + .. tab:: + :tabid: dart + + .. tab:: + :tabid: java + + + .. tab:: + :tabid: java-kotlin + + + .. tab:: + :tabid: javascript + + + .. tab:: + :tabid: kotlin + + .. include:: /includes/api-details/kotlin/users/custom-user-data-delete-custom-user-data-description.rst + + .. tab:: + :tabid: objectivec + + + .. tab:: + :tabid: swift + + + .. tab:: + :tabid: typescript + + +.. include:: /includes/sdk-examples/users/custom-user-data-delete-custom-user-data.rst