Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
3 changes: 2 additions & 1 deletion snooty.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
11 changes: 6 additions & 5 deletions source/data-modeling.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ Model Your Data
.. meta::
:keywords: ruby framework, odm, model, class, query

.. .. toctree::
.. :caption: Data Modeling
..
.. Documents </data-modeling/documents>
.. toctree::
:caption: Data Modeling

Documents </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``
module.
93 changes: 93 additions & 0 deletions source/data-modeling/documents.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
.. _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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{+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 represents a MongoDB
document. To learn more about the terminology, structure, and limitations of

MongoDB documents, see :manual:`Documents </core/document/>` 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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

S: in my opinion, main focus of this section is an example on using the .create() method - might be worth changing the title to reflect that.

And/or, the representation paragraph kinda feels like it splits apart the section about the Document class and its methods. Some alternatives could be moving the below method example to the preceding section (and leaving this title as is), or putting the representation paragraph into an admonition.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved the text around/reworded

----------------------

The representation of a ``Document`` in MongoDB is a BSON object that is
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The representation of a ``Document`` in MongoDB is a BSON object that is
A ``Document`` in MongoDB is represented by a BSON object that is

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reworded

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
of your models directly in a collection in the database, or you can
of your models directly in a collection, or you can

or "database collection"?

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
:copyable: false

{
"_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
</reference/bson-types/#objectid>` 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.

.. TODO Add link to field types guide.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm assuming this guide hasn't been created yet, but pointing this out just in case it has!

Loading