-
Notifications
You must be signed in to change notification settings - Fork 29
DOCSP-42743 Collection config #95
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
Merged
jordan-smith721
merged 3 commits into
mongodb:standardized
from
jordan-smith721:DOCSP-42743-collection-config
Jan 24, 2025
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
.. _mongoid-collection-config: | ||
|
||
======================== | ||
Collection Configuration | ||
======================== | ||
|
||
.. facet:: | ||
:name: genre | ||
:values: reference | ||
|
||
.. meta:: | ||
:keywords: code example, collections, time series, capped collection | ||
|
||
.. contents:: On this page | ||
:local: | ||
:backlinks: none | ||
:depth: 2 | ||
:class: singlecol | ||
|
||
Overview | ||
-------- | ||
|
||
In this guide, you can learn how to specify configuration options for a | ||
collection in your {+odm+} application. | ||
|
||
Configure Collection Options | ||
---------------------------- | ||
|
||
You can specify configuration options for a collection by using the | ||
``:collection_options`` argument with the ``store_in`` | ||
macro. The ``:collection_options`` argument accepts any collection option that | ||
your {+ruby-driver+} and MongoDB server version supports. | ||
|
||
.. note:: | ||
|
||
You must explicitly create a collection to apply any specified collection | ||
options. Create your collection by running the collection management Rake task, as | ||
shown in :ref:`mongoid-create-collection-rake` section of this guide. | ||
|
||
To learn more about collection options available in the {+ruby-driver+}, see the | ||
:ruby:`Collections </reference/collection-tasks/>` guide in the {+ruby-driver+} | ||
documentation. | ||
|
||
The following sections show examples of how to configure collection options when | ||
using {+odm+}. | ||
|
||
Time Series Collection | ||
~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
Time series collections efficiently store sequences of measurements over a | ||
period of time. The following example shows how to configure a time series | ||
collection: | ||
|
||
.. literalinclude:: /includes/configuration/collection-config.rb | ||
:language: ruby | ||
:start-after: # start-time-series-config | ||
:end-before: # end-time-series-config | ||
:emphasize-lines: 7-13 | ||
|
||
To learn more about time series collections, see the :manual:`Time Series Collections | ||
</core/timeseries-collections/#time-series-collections/>` guide in the MongoDB {+server-manual+}. | ||
|
||
Capped Collection | ||
~~~~~~~~~~~~~~~~~ | ||
|
||
Capped collections have maximum size or document counts that prevent them from | ||
growing beyond a specified threshold. The following example shows how to configure | ||
a capped collection: | ||
|
||
rustagir marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.. literalinclude:: /includes/configuration/collection-config.rb | ||
:language: ruby | ||
:start-after: # start-capped-collection-config | ||
:end-before: # end-capped-collection-config | ||
:emphasize-lines: 4-7 | ||
|
||
To learn more about capped collections, see the :manual:`Capped Collections | ||
</core/capped-collections/>` guide in the MongoDB {+server-manual+}. | ||
|
||
Default Collation | ||
~~~~~~~~~~~~~~~~~ | ||
|
||
Collations are sets of rules for how to compare strings, typically in a | ||
particular natural language. The following example shows how to specify a | ||
default collation to use on a | ||
collection: | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. S: same comment about explaining + linking |
||
.. literalinclude:: /includes/configuration/collection-config.rb | ||
:language: ruby | ||
:start-after: # start-default-collation-config | ||
:end-before: # end-default-collation-config | ||
:emphasize-lines: 4-8 | ||
|
||
To learn more about collations, see the :manual:`Collation | ||
</reference/collation/>` guide in the MongoDB {+server-manual+}. | ||
|
||
.. _mongoid-create-collection-rake: | ||
|
||
Collection Management Rake Task | ||
------------------------------- | ||
|
||
To apply the collection options you specify in your {+odm+} application, you | ||
must explicitly create the corresponding collection. To do so, use the | ||
``db:mongoid:create_collections`` Rake task by running the following command in | ||
your shell: | ||
|
||
.. code-block:: bash | ||
|
||
rake db:mongoid:create_collections | ||
|
||
You can also run the ``create_collection`` command on a single model in the | ||
Rails console, as shown in the following example: | ||
|
||
.. code-block:: ruby | ||
|
||
Model.create_collection |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# start-time-series-config | ||
class Measurement | ||
include Mongoid::Document | ||
|
||
field :temperature, type: Integer | ||
field :timestamp, type: Time | ||
|
||
store_in collection_options: { | ||
time_series: { | ||
timeField: "timestamp", | ||
granularity: "minutes" | ||
}, | ||
expire_after: 604800 | ||
} | ||
end | ||
# end-time-series-config | ||
|
||
# start-capped-collection-config | ||
class Blog | ||
include Mongoid::Document | ||
|
||
store_in collection_options: { | ||
capped: true, | ||
size: 1024 | ||
} | ||
end | ||
# end-capped-collection-config | ||
|
||
# start-default-collation-config | ||
class Title | ||
include Mongoid::Document | ||
|
||
store_in collection_options: { | ||
collation: { | ||
locale: 'fr' | ||
} | ||
} | ||
end | ||
# end-default-collation-config |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.