Skip to content

Commit 644c525

Browse files
committed
DOCSP-45358: documents
1 parent b705149 commit 644c525

File tree

2 files changed

+65
-5
lines changed

2 files changed

+65
-5
lines changed

source/data-modeling.txt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ Model Your Data
1111
.. meta::
1212
:keywords: ruby framework, odm, model, class, query
1313

14-
.. .. toctree::
15-
.. :caption: Data Modeling
16-
..
17-
.. Documents </data-modeling/documents>
14+
.. toctree::
15+
:caption: Data Modeling
16+
17+
Documents </data-modeling/documents>
1818

1919
In this section, you can learn how to model data in {+odm+}.
2020

21-
.. - :ref:``: Learn how to ...
21+
- :ref:`mongoid-modeling-documents`: Learn about the ``Document`` object
22+
type.

source/data-modeling/documents.txt

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
.. _mongoid-modeling-documents:
2+
3+
=========
4+
Documents
5+
=========
6+
7+
.. facet::
8+
:name: genre
9+
:values: reference
10+
11+
.. meta::
12+
:keywords: ruby framework, odm, code example, bson
13+
14+
.. contents:: On this page
15+
:local:
16+
:backlinks: none
17+
:depth: 2
18+
:class: singlecol
19+
20+
Overview
21+
--------
22+
23+
In this guide, you can learn about the ``Mongoid::Document`` module in
24+
{+odm+}. The ``Document`` module is a representation of a MongoDB
25+
document. To learn more about the terminology, structure, and limitations of
26+
MongoDB documents, see :manual:`Documents </core/document/>` in the
27+
{+server-manual+}.
28+
29+
You must include the ``Mongoid::Document`` module in any class that you
30+
want to persist to MongoDB. By including the ``Document`` module in your
31+
model class, you can use its methods on instances of your model class.
32+
33+
The following code demonstrates how to include the ``Document`` module
34+
in a sample ``Person`` model class:
35+
36+
.. code-block:: ruby
37+
:emphasize-lines: 2
38+
39+
class Person
40+
include Mongoid::Document
41+
42+
field :name, type: String
43+
end
44+
45+
You can find more information about the ``Document`` module in the `API
46+
documentation <{+api-root+}/Document.html>`__.
47+
48+
MongoDB Representation
49+
----------------------
50+
51+
The representation of a ``Document`` in MongoDB is a BSON object that is
52+
similar to a {+language+} hash or JSON object. You can store instances
53+
of your models directly in a collection in the database, or you can
54+
embed them in other classes that use the ``Document`` module.
55+
56+
To learn more about how to model your data by using {+odm+} models,
57+
see the :ref:`mongoid-data-modeling` guides.
58+
59+
.. TODO Add link to field types guide.

0 commit comments

Comments
 (0)