From 644c525a41fb4223a21eda956ced42bb2a812fc6 Mon Sep 17 00:00:00 2001 From: rustagir Date: Mon, 18 Nov 2024 11:22:27 -0500 Subject: [PATCH 1/5] DOCSP-45358: documents --- source/data-modeling.txt | 11 +++--- source/data-modeling/documents.txt | 59 ++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 5 deletions(-) create mode 100644 source/data-modeling/documents.txt diff --git a/source/data-modeling.txt b/source/data-modeling.txt index 45c78994..1a81e1a8 100644 --- a/source/data-modeling.txt +++ b/source/data-modeling.txt @@ -11,11 +11,12 @@ Model Your Data .. meta:: :keywords: ruby framework, odm, model, class, query -.. .. toctree:: -.. :caption: Data Modeling -.. -.. Documents +.. toctree:: + :caption: Data Modeling + + Documents In this section, you can learn how to model data in {+odm+}. -.. - :ref:``: Learn how to ... +- :ref:`mongoid-modeling-documents`: Learn about the ``Document`` object + type. diff --git a/source/data-modeling/documents.txt b/source/data-modeling/documents.txt new file mode 100644 index 00000000..0a3e1f6a --- /dev/null +++ b/source/data-modeling/documents.txt @@ -0,0 +1,59 @@ +.. _mongoid-modeling-documents: + +========= +Documents +========= + +.. facet:: + :name: genre + :values: reference + +.. meta:: + :keywords: ruby framework, odm, code example, bson + +.. contents:: On this page + :local: + :backlinks: none + :depth: 2 + :class: singlecol + +Overview +-------- + +In this guide, you can learn about the ``Mongoid::Document`` module in +{+odm+}. The ``Document`` module is a representation of a MongoDB +document. To learn more about the terminology, structure, and limitations of +MongoDB documents, see :manual:`Documents ` in the +{+server-manual+}. + +You must include the ``Mongoid::Document`` module in any class that you +want to persist to MongoDB. By including the ``Document`` module in your +model class, you can use its methods on instances of your model class. + +The following code demonstrates how to include the ``Document`` module +in a sample ``Person`` model class: + +.. code-block:: ruby + :emphasize-lines: 2 + + class Person + include Mongoid::Document + + field :name, type: String + end + +You can find more information about the ``Document`` module in the `API +documentation <{+api-root+}/Document.html>`__. + +MongoDB Representation +---------------------- + +The representation of a ``Document`` in MongoDB is a BSON object that is +similar to a {+language+} hash or JSON object. You can store instances +of your models directly in a collection in the database, or you can +embed them in other classes that use the ``Document`` module. + +To learn more about how to model your data by using {+odm+} models, +see the :ref:`mongoid-data-modeling` guides. + +.. TODO Add link to field types guide. From a474e123966bd1c95d8cb40c04ef06d054ef5605 Mon Sep 17 00:00:00 2001 From: rustagir Date: Mon, 18 Nov 2024 11:23:16 -0500 Subject: [PATCH 2/5] fix --- source/data-modeling.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/data-modeling.txt b/source/data-modeling.txt index 1a81e1a8..88bdc04f 100644 --- a/source/data-modeling.txt +++ b/source/data-modeling.txt @@ -18,5 +18,5 @@ Model Your Data In this section, you can learn how to model data in {+odm+}. -- :ref:`mongoid-modeling-documents`: Learn about the ``Document`` object - type. +- :ref:`mongoid-modeling-documents`: Learn about the ``Document`` + module. From 0c5c569b805618e5d4c430d205b62d3e3b4c512d Mon Sep 17 00:00:00 2001 From: rustagir Date: Mon, 18 Nov 2024 11:42:01 -0500 Subject: [PATCH 3/5] wip --- snooty.toml | 3 ++- source/data-modeling/documents.txt | 33 ++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/snooty.toml b/snooty.toml index 5b4584c2..04a3ea10 100644 --- a/snooty.toml +++ b/snooty.toml @@ -10,7 +10,8 @@ toc_landing_pages = [ "/quick-start-rails", "/quick-start-sinatra", "/interact-data", - "/interact-data/specify-query" + "/interact-data/specify-query", + "/data-modeling" ] [constants] diff --git a/source/data-modeling/documents.txt b/source/data-modeling/documents.txt index 0a3e1f6a..8503ec3a 100644 --- a/source/data-modeling/documents.txt +++ b/source/data-modeling/documents.txt @@ -53,6 +53,39 @@ similar to a {+language+} hash or JSON object. You can store instances of your models directly in a collection in the database, or you can embed them in other classes that use the ``Document`` module. +The following code creates an instance of the ``Person`` model defined +in the preceding section: + +.. code-block:: ruby + + Person.create(name: 'Meena Kumar') + +The document appears in MongoDB as follows: + +.. code-block:: json + + { + "_id": { + "$oid": "673b6dce61700598c24a72b0" + }, + "name": "Meena Kumar" + } + +.. note:: _id Field + + When you persist an instance of a model to the database, MongoDB + automatically adds an ``_id`` field that has a unique value even if you + do not explicitly define this field in your model. + + To learn more about this field, see the :manual:`ObjectId reference + ` in the {+server-manual+}. + +Additional Information +---------------------- + +To learn how to access and change your MongoDB data, see the +:ref:`mongoid-interact-data` guides. + To learn more about how to model your data by using {+odm+} models, see the :ref:`mongoid-data-modeling` guides. From d2e3f1c4d32a19fafff3a234f82b77ac42b7c2b8 Mon Sep 17 00:00:00 2001 From: rustagir Date: Mon, 18 Nov 2024 11:44:59 -0500 Subject: [PATCH 4/5] wip --- source/data-modeling/documents.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/source/data-modeling/documents.txt b/source/data-modeling/documents.txt index 8503ec3a..a8c9d4a6 100644 --- a/source/data-modeling/documents.txt +++ b/source/data-modeling/documents.txt @@ -63,6 +63,7 @@ in the preceding section: The document appears in MongoDB as follows: .. code-block:: json + :copyable: false { "_id": { From b217789a8f7ece6c813a448379cd131c6ce911ed Mon Sep 17 00:00:00 2001 From: rustagir Date: Wed, 20 Nov 2024 09:55:37 -0500 Subject: [PATCH 5/5] MR PR fixes 1 --- source/data-modeling/documents.txt | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/source/data-modeling/documents.txt b/source/data-modeling/documents.txt index a8c9d4a6..5fcbea93 100644 --- a/source/data-modeling/documents.txt +++ b/source/data-modeling/documents.txt @@ -21,8 +21,9 @@ Overview -------- In this guide, you can learn about the ``Mongoid::Document`` module in -{+odm+}. The ``Document`` module is a representation of a MongoDB -document. To learn more about the terminology, structure, and limitations of +{+odm+}. The ``Document`` module is a {+language+} implementation of a +MongoDB document, which stores data in field-and-value pairs. To learn +more about the terminology, structure, and limitations of MongoDB documents, see :manual:`Documents ` in the {+server-manual+}. @@ -45,13 +46,14 @@ in a sample ``Person`` model class: You can find more information about the ``Document`` module in the `API documentation <{+api-root+}/Document.html>`__. -MongoDB Representation ----------------------- +Work with Documents +------------------- -The representation of a ``Document`` in MongoDB is a BSON object that is -similar to a {+language+} hash or JSON object. You can store instances -of your models directly in a collection in the database, or you can -embed them in other classes that use the ``Document`` module. +You can store instances of your models directly in a collection, or you +can embed them in other classes that use the ``Document`` module. +When you save a ``Document`` instance to MongoDB, it is converted +to a BSON object that is similar to a {+language+} hash or JSON +object. The following code creates an instance of the ``Person`` model defined in the preceding section: