Skip to content
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

DOCSP-37133: Collections in Mixed data type #715

Merged
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 1 addition & 1 deletion source/graphql/expose-data.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ field, the field has a ``null`` value in the returned document.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

GraphQL requires that all data conforms to a well-defined type, so you
must :ref:`define a schema <enforce-a-schema>` for
must :ref:`enforce-a-schema` for
documents in the collection. App Services automatically generates
:doc:`GraphQL types and resolvers
</graphql/types-and-resolvers>` for documents in the collection
Expand Down
23 changes: 23 additions & 0 deletions source/includes/note-collections-in-mixed-sync.rst
cbullinger marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.. note:: Collections in Mixed fields supported in Apps created after March XX, 2024
cbullinger marked this conversation as resolved.
Show resolved Hide resolved

App Services Apps created *after* March XX, 2024 can store collections
cbullinger marked this conversation as resolved.
Show resolved Hide resolved
cbullinger marked this conversation as resolved.
Show resolved Hide resolved
(arrays and dictionaries) in mixed data properties. This lets you
nest collections within other collections, and store complex data
structures in a single property.

To use feature with Atlas Device SDK, you must use :ref:`Flutter SDK v2.0.0 or later <flutter-realm-value>`. Support for other SDKs will be added in future releases.
cbullinger marked this conversation as resolved.
Show resolved Hide resolved

If your App was created before March XX, 2024, you can contact support to
learn more about enabling this feature.

.. TODO: Update this note with SDK versions once they release
.. To use this feature with an Atlas Device SDK, you must use the following
SDK versions:
.. - C++ SDK v1.0.0 or later
.. - Flutter SDK v2.0.0 or later
.. - Kotlin SDK v1.0.0 or later
.. - .NET SDK v1.0.0 or later
.. - Node.js SDK v1.0.0 or later
.. - React Native SDK v1.0.0 or later
.. - Swift SDK v1.0.0 or later
.. - This feature is *not* supported in the Java SDK
11 changes: 8 additions & 3 deletions source/schemas.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
Schemas
=======

.. default-domain:: mongodb
.. meta::
:description: Learn about Atlas App Services Schemas.

.. facet::
:name: genre
:values: reference

.. contents:: On this page
:local:
Expand All @@ -15,9 +20,9 @@ Schemas
.. toctree::
:titlesonly:

Enforce a Schema </schemas/enforce-a-schema>
Define & Enforce a Schema </schemas/enforce-a-schema>
Remove a Schema </schemas/remove-a-schema>
Schema Types </schemas/types>
Schema Data Types </schemas/types>

Overview
--------
Expand Down
44 changes: 32 additions & 12 deletions source/schemas/enforce-a-schema.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
.. _enforce-a-schema:
.. _define-a-schema:

================
Enforce a Schema
================
=========================
Define & Enforce a Schema
=========================

.. default-domain:: mongodb
.. meta::
:keywords: code example
:description: Learn how to create and deploy an Atlas App Services Schema and define validation rules to enforce it.

.. facet::
:name: genre
:values: reference

.. facet::
:name: programming_language
:values: json

.. contents:: On this page
:local:
Expand All @@ -25,8 +36,16 @@ MongoDB Atlas collection.

.. include:: /includes/adf-rules-note.rst

Procedure
---------
Define a Schema
---------------

You can define a schema for a collection in the App Services UI or with the
{+cli-bin+}.
cbullinger marked this conversation as resolved.
Show resolved Hide resolved

When using the App Services UI, you can choose to:

- Generate a schema from existing data in the collection, and modify as needed.
- Define a schema manually by adding field-level schema definitions.

.. tabs-realm-admin-interfaces::

Expand All @@ -46,11 +65,11 @@ Procedure
configuration screen.


.. step:: Generate a Schema
.. step:: Generate a Schema from Existing Data (Optional)

If you already have data in your collection, App Services can
sample a subset of the documents in the collection and generate a
schema for you based on the sample. This step is optional, so if you
schema for you based on the sample. If you
already have a schema or prefer to define one manually, skip this
step.

Expand Down Expand Up @@ -80,7 +99,9 @@ Procedure
:alt: The Generate Schema sample size input in the App Services UI


.. step:: Add Field-Level Schema Definitions
.. step:: Define or Modify the Schema

You can define a schema manually or modify an existing schema by adding field-level schema definitions.

You may define a single BSON schema for each collection. The root-level type
of each collection schema is an ``object`` schema that represents a document
Expand Down Expand Up @@ -149,8 +170,7 @@ Procedure
}
}


.. step:: Add Change Validation Expressions
.. step:: Add Change Validation Expressions (Optional)

In addition to configuring the content of each field, you can validate changes
to documents by defining a validation :ref:`expression <expressions>` in the
Expand Down Expand Up @@ -308,7 +328,7 @@ Procedure
}


.. step:: Define Change Validation
.. step:: Define Change Validation (Optional)

You can validate changes to documents by defining a validation
:ref:`expression <expressions>` in the ``validate`` field of a schema.
Expand Down
190 changes: 99 additions & 91 deletions source/schemas/relationships.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,17 @@
Relationships
=============

.. default-domain:: mongodb
.. meta::
:keywords: code example
:description: Learn about relationship types and how to define them in an Atlas App Services Schema.

.. facet::
:name: genre
:values: reference

.. facet::
:name: programming_language
:values: json, shell

.. contents:: On this page
:local:
Expand Down Expand Up @@ -259,7 +269,7 @@ with a foreign collection.
}
}

To access a embedded object property contained in a list, use:
To access an embedded object property contained in a list, use:
``field1.[].field2``, e.g. ``pets.[].favoriteToyBrand``. From there,
you can specify the foreign collection details and foreign key field.

Expand Down Expand Up @@ -296,104 +306,102 @@ When you define a relationship, keep these limitations in mind:
- The reference field must not be a ``required`` field
- The foreign key must be the ``_id`` field of the collection the field is referencing

1. Define Schemas
~~~~~~~~~~~~~~~~~
.. procedure::

In order to define a relationship, you must have a schema defined for
both the source collection and the foreign collection. To learn how to
define schemas, see :ref:`enforce-a-schema`.
.. step:: Define Schemas

2. Create a New Relationship
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In order to define a relationship, you must have a schema defined for
both the source collection and the foreign collection. To learn how to
define schemas, see :ref:`enforce-a-schema`.

You define a relationship for collections in a linked MongoDB data
source alongside the schema.
.. step:: Create a New Relationship

.. tabs-realm-admin-interfaces::
You define a relationship for collections in a linked MongoDB data
source alongside the schema.

.. tab::
:tabid: ui

To create a new relationship:

1. Click :guilabel:`Schema` in the left navigation menu

2. Click the :guilabel:`Relationships` tab

3. Click :guilabel:`Add Relationship`

.. tab::
:tabid: cli
.. tabs-realm-admin-interfaces::

To create a new relationship, add a relationship configuration
object to the source collection's ``relationships.json`` file:
.. tab::
:tabid: ui

.. code-block:: json

{
"<source field>": {
"ref": "#/relationship/<data source>/<db>/<collection>",
"foreign_key": "<foreign field>",
"is_list": <boolean>
}
}
To create a new relationship:

1. Click :guilabel:`Schema` in the left navigation menu

3. Configure the Relationship
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2. Click the :guilabel:`Relationships` tab

A relationship definition maps from a field included in the source
collection's schema and points to a field of the same type in the
foreign collection's schema.
3. Click :guilabel:`Add Relationship`

.. tab::
:tabid: cli

.. tabs-realm-admin-interfaces::
To create a new relationship, add a relationship configuration
object to the source collection's ``relationships.json`` file:

.. tab::
:tabid: ui

To configure the relationship:

1. Specify a field in the source collection to create the relationship on

2. Specify the foreign database, collection, and a field in the
foreign collection to match with the source field

3. Click :guilabel:`Add`

.. tab::
:tabid: cli

To configure the relationship, specify the source field name as a
root-level field in ``relationships.json`` and then add the
following configuration options in the field's value:

- Specify the foreign collection in the ``ref`` field using the
following format:
.. code-block:: json

.. code-block:: text

#/relationship/<data source>/<db>/<collection>

- Specify the field to match in the ``foreign_key`` field

- If the source field contains an array, set ``is_list`` to
``true``, otherwise set it to ``false``.

4. Deploy the Relationship
~~~~~~~~~~~~~~~~~~~~~~~~~~

.. tabs-realm-admin-interfaces::

.. tab::
:tabid: ui

Click :guilabel:`Save` and then deploy your updated application.

.. tab::
:tabid: cli

Save the relationship configuration file and push your changes to
deploy them:

.. code-block:: sh

{+cli-bin+} push
{
"<source field>": {
"ref": "#/relationship/<data source>/<db>/<collection>",
"foreign_key": "<foreign field>",
"is_list": <boolean>
}
}

.. step:: Configure the Relationship

A relationship definition maps from a field included in the source
collection's schema and points to a field of the same type in the
foreign collection's schema.

.. tabs-realm-admin-interfaces::

.. tab::
:tabid: ui

To configure the relationship:

1. Specify a field in the source collection to create the relationship on
cbullinger marked this conversation as resolved.
Show resolved Hide resolved

2. Specify the foreign database, collection, and a field in the
cbullinger marked this conversation as resolved.
Show resolved Hide resolved
foreign collection to match with the source field

3. Click :guilabel:`Add`

.. tab::
:tabid: cli

To configure the relationship, specify the source field name as a
root-level field in ``relationships.json`` and then add the
following configuration options in the field's value:

- Specify the foreign collection in the ``ref`` field using the
following format:

.. code-block:: text

#/relationship/<data source>/<db>/<collection>

- Specify the field to match in the ``foreign_key`` field

- If the source field contains an array, set ``is_list`` to
``true``, otherwise set it to ``false``.

.. step:: Deploy the Relationship

.. tabs-realm-admin-interfaces::

.. tab::
:tabid: ui

Click :guilabel:`Save` and then deploy your updated application.

.. tab::
:tabid: cli

Save the relationship configuration file and push your changes to
deploy them:

.. code-block:: sh

{+cli-bin+} push
Loading
Loading