Skip to content

Commit d6c6932

Browse files
author
hiroshi
committed
bin/rails g mongoid:config
1 parent 5ace928 commit d6c6932

File tree

4 files changed

+335
-1
lines changed

4 files changed

+335
-1
lines changed

Gemfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
source "https://rubygems.org"
22

3-
# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
43
gem "rails", "~> 8.0.2"
54
gem 'vite_rails'
5+
gem 'mongoid'
6+
67
# The modern asset pipeline for Rails [https://github.com/rails/propshaft]
78
gem "propshaft"
89
# Use sqlite3 as the database for Active Record

Gemfile.lock

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ GEM
8484
msgpack (~> 1.2)
8585
brakeman (7.1.0)
8686
racc
87+
bson (5.1.1)
8788
builder (3.3.0)
8889
capybara (3.40.0)
8990
addressable
@@ -155,6 +156,13 @@ GEM
155156
matrix (0.4.3)
156157
mini_mime (1.1.5)
157158
minitest (5.25.5)
159+
mongo (2.21.2)
160+
base64
161+
bson (>= 4.14.1, < 6.0.0)
162+
mongoid (9.0.7)
163+
activemodel (>= 5.1, < 8.1, != 7.0.0)
164+
concurrent-ruby (>= 1.0.5, < 2.0)
165+
mongo (>= 2.18.0, < 3.0.0)
158166
msgpack (1.8.0)
159167
mutex_m (0.3.0)
160168
net-imap (0.5.9)
@@ -379,6 +387,7 @@ DEPENDENCIES
379387
importmap-rails
380388
jbuilder
381389
kamal
390+
mongoid
382391
propshaft
383392
puma (>= 5.0)
384393
rails (~> 8.0.2)

config/initializers/mongoid.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# rubocop:todo all
2+
Mongoid.configure do
3+
target_version = "9.0"
4+
5+
# Load Mongoid behavior defaults. This automatically sets
6+
# features flags (refer to documentation)
7+
config.load_defaults target_version
8+
9+
# It is recommended to use config/mongoid.yml for most Mongoid-related
10+
# configuration, whenever possible, but if you prefer, you can set
11+
# configuration values here, instead:
12+
#
13+
# config.log_level = :debug
14+
#
15+
# Note that the settings in config/mongoid.yml always take precedence,
16+
# whatever else is set here.
17+
end
18+
19+
# Enable Mongo driver query cache for Rack
20+
# Rails.application.config.middleware.use(Mongo::QueryCache::Middleware)
21+
22+
# Enable Mongo driver query cache for ActiveJob
23+
# ActiveSupport.on_load(:active_job) do
24+
# include Mongo::QueryCache::Middleware::ActiveJob
25+
# end

config/mongoid.yml

Lines changed: 299 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,299 @@
1+
development:
2+
# Configure available database clients. (required)
3+
clients:
4+
# Defines the default client. (required)
5+
default:
6+
# Mongoid can connect to a URI accepted by the driver:
7+
# uri: mongodb://user:[email protected]:27017/app_development
8+
9+
# Otherwise define the parameters separately.
10+
# This defines the name of the default database that Mongoid can connect to.
11+
# (required).
12+
database: app_development
13+
# Provides the hosts the default client can connect to. Must be an array
14+
# of host:port pairs. (required)
15+
hosts:
16+
- localhost:27017
17+
options:
18+
# Note that all options listed below are Ruby driver client options (the mongo gem).
19+
# Please refer to the driver documentation of the version of the mongo gem you are using
20+
# for the most up-to-date list of options.
21+
22+
# Change the default write concern. (default = { w: 1 })
23+
# write:
24+
# w: 1
25+
26+
# Change the default read preference. Valid options for mode are: :secondary,
27+
# :secondary_preferred, :primary, :primary_preferred, :nearest
28+
# (default: primary)
29+
# read:
30+
# mode: :secondary_preferred
31+
# tag_sets:
32+
# - use: web
33+
34+
# The name of the user for authentication.
35+
# user: 'user'
36+
37+
# The password of the user for authentication.
38+
# password: 'password'
39+
40+
# The user's database roles.
41+
# roles:
42+
# - 'dbOwner'
43+
44+
# Change the default authentication mechanism. Valid options include:
45+
# :scram, :scram256, :mongodb_cr, :mongodb_x509, :gssapi, :aws, :plain.
46+
# MongoDB Server defaults to :scram, which will use "SCRAM-SHA-256" if available,
47+
# otherwise fallback to "SCRAM-SHA-1" (:scram256 will always use "SCRAM-SHA-256".)
48+
# This setting is handled by the MongoDB Ruby Driver. Please refer to:
49+
# https://mongodb.com/docs/ruby-driver/current/reference/authentication/
50+
# auth_mech: :scram
51+
52+
# The database or source to authenticate the user against.
53+
# (default: the database specified above or admin)
54+
# auth_source: admin
55+
56+
# Force the driver cluster to behave in a certain manner instead of auto-discovering.
57+
# Can be one of: :direct, :replica_set, :sharded. Set to :direct
58+
# when connecting to hidden members of a replica set.
59+
# connect: :direct
60+
61+
# Changes the default time in seconds the server monitors refresh their status
62+
# via hello commands. (default: 10)
63+
# heartbeat_frequency: 10
64+
65+
# The time in seconds for selecting servers for a near read preference. (default: 0.015)
66+
# local_threshold: 0.015
67+
68+
# The timeout in seconds for selecting a server for an operation. (default: 30)
69+
# server_selection_timeout: 30
70+
71+
# The maximum number of connections in the connection pool. (default: 5)
72+
# max_pool_size: 5
73+
74+
# The minimum number of connections in the connection pool. (default: 1)
75+
# min_pool_size: 1
76+
77+
# The time to wait, in seconds, in the connection pool for a connection
78+
# to be checked in before timing out. (default: 5)
79+
# wait_queue_timeout: 5
80+
81+
# The time to wait to establish a connection before timing out, in seconds.
82+
# (default: 10)
83+
# connect_timeout: 10
84+
85+
# How long to wait for a response for each operation sent to the
86+
# server. This timeout should be set to a value larger than the
87+
# processing time for the longest operation that will be executed
88+
# by the application. Note that this is a client-side timeout;
89+
# the server may continue executing an operation after the client
90+
# aborts it with the SocketTimeout exception.
91+
# (default: nil, meaning no timeout)
92+
# socket_timeout: 5
93+
94+
# The name of the replica set to connect to. Servers provided as seeds that do
95+
# not belong to this replica set will be ignored.
96+
# replica_set: name
97+
98+
# Compressors to use for wire protocol compression. (default is to not use compression)
99+
# "zstd" requires zstd-ruby gem. "snappy" requires snappy gem.
100+
# Refer to: https://www.mongodb.com/docs/ruby-driver/current/reference/create-client/#compression
101+
# compressors: ["zstd", "snappy", "zlib"]
102+
103+
# Whether to connect to the servers via ssl. (default: false)
104+
# ssl: true
105+
106+
# The certificate file used to identify the connection against MongoDB.
107+
# ssl_cert: /path/to/my.cert
108+
109+
# The private keyfile used to identify the connection against MongoDB.
110+
# Note that even if the key is stored in the same file as the certificate,
111+
# both need to be explicitly specified.
112+
# ssl_key: /path/to/my.key
113+
114+
# A passphrase for the private key.
115+
# ssl_key_pass_phrase: password
116+
117+
# Whether to do peer certification validation. (default: true)
118+
# ssl_verify: true
119+
120+
# The file containing concatenated certificate authority certificates
121+
# used to validate certs passed from the other end of the connection.
122+
# ssl_ca_cert: /path/to/ca.cert
123+
124+
# Whether to truncate long log lines. (default: true)
125+
# truncate_logs: true
126+
127+
# Configure Mongoid-specific options. (optional)
128+
options:
129+
# Allow BSON::Decimal128 to be parsed and returned directly in
130+
# field values. When BSON 5 is present and the this option is set to false
131+
# (the default), BSON::Decimal128 values in the database will be returned
132+
# as BigDecimal.
133+
#
134+
# @note this option only has effect when BSON 5+ is present. Otherwise,
135+
# the setting is ignored.
136+
# allow_bson5_decimal128: false
137+
138+
# When this flag is false, named scopes cannot unset a default scope.
139+
# This is the traditional (and default) behavior in Mongoid 9 and earlier.
140+
#
141+
# Setting this flag to true will allow named scopes to unset the default
142+
# scope. This will be the default in Mongoid 10.
143+
#
144+
# See https://jira.mongodb.org/browse/MONGOID-5785 for more details.
145+
# allow_scopes_to_unset_default_scope: false
146+
147+
# Application name that is printed to the MongoDB logs upon establishing
148+
# a connection. Note that the name cannot exceed 128 bytes in length.
149+
# It is also used as the database name if the database name is not
150+
# explicitly defined.
151+
# app_name: nil
152+
153+
# When this flag is false, callbacks for embedded documents will not be
154+
# called. This is the default in 9.0.
155+
#
156+
# Setting this flag to true restores the pre-9.0 behavior, where callbacks
157+
# for embedded documents are called. This may lead to stack overflow errors
158+
# if there are more than cicrca 1000 embedded documents in the root
159+
# document's dependencies graph.
160+
# See https://jira.mongodb.org/browse/MONGOID-5658 for more details.
161+
# around_callbacks_for_embeds: false
162+
163+
# Sets the async_query_executor for the application. By default the thread pool executor
164+
# is set to `:immediate. Options are:
165+
#
166+
# - :immediate - Initializes a single +Concurrent::ImmediateExecutor+
167+
# - :global_thread_pool - Initializes a single +Concurrent::ThreadPoolExecutor+
168+
# that uses the +async_query_concurrency+ for the +max_threads+ value.
169+
# async_query_executor: :immediate
170+
171+
# Mark belongs_to associations as required by default, so that saving a
172+
# model with a missing belongs_to association will trigger a validation
173+
# error.
174+
# belongs_to_required_by_default: true
175+
176+
# Set the global discriminator key.
177+
# discriminator_key: "_type"
178+
179+
# Raise an exception when a field is redefined.
180+
# duplicate_fields_exception: false
181+
182+
# Defines how many asynchronous queries can be executed concurrently.
183+
# This option should be set only if `async_query_executor` is set
184+
# to `:global_thread_pool`.
185+
# global_executor_concurrency: nil
186+
187+
# When this flag is true, any attempt to change the _id of a persisted
188+
# document will raise an exception (`Errors::ImmutableAttribute`).
189+
# This is the default in 9.0. Setting this flag to false restores the
190+
# pre-9.0 behavior, where changing the _id of a persisted
191+
# document might be ignored, or it might work, depending on the situation.
192+
# immutable_ids: true
193+
194+
# Include the root model name in json serialization.
195+
# include_root_in_json: false
196+
197+
# # Include the _type field in serialization.
198+
# include_type_for_serialization: false
199+
200+
# Whether to join nested persistence contexts for atomic operations
201+
# to parent contexts by default.
202+
# join_contexts: false
203+
204+
# When this flag is false (the default as of Mongoid 9.0), a document that
205+
# is created or loaded will remember the storage options that were active
206+
# when it was loaded, and will use those same options by default when
207+
# saving or reloading itself.
208+
#
209+
# When this flag is true you'll get pre-9.0 behavior, where a document will
210+
# not remember the storage options from when it was loaded/created, and
211+
# subsequent updates will need to explicitly set up those options each time.
212+
#
213+
# For example:
214+
#
215+
# record = Model.with(collection: 'other_collection') { Model.first }
216+
#
217+
# This will try to load the first document from 'other_collection' and
218+
# instantiate it as a Model instance. Pre-9.0, the record object would
219+
# not remember that it came from 'other_collection', and attempts to
220+
# update it or reload it would fail unless you first remembered to
221+
# explicitly specify the collection every time.
222+
#
223+
# As of Mongoid 9.0, the record will remember that it came from
224+
# 'other_collection', and updates and reloads will automatically default
225+
# to that collection, for that record object.
226+
# legacy_persistence_context_behavior: false
227+
228+
# When this flag is false, a document will become read-only only once the
229+
# #readonly! method is called, and an error will be raised on attempting
230+
# to save or update such documents, instead of just on delete. When this
231+
# flag is true, a document is only read-only if it has been projected
232+
# using #only or #without, and read-only documents will not be
233+
# deletable/destroyable, but they will be savable/updatable.
234+
# When this feature flag is turned on, the read-only state will be reset on
235+
# reload, but when it is turned off, it won't be.
236+
# legacy_readonly: false
237+
238+
# The log level.
239+
#
240+
# It must be set prior to referencing clients or Mongo.logger,
241+
# changes to this option are not be propagated to any clients and
242+
# loggers that already exist.
243+
#
244+
# Additionally, only when the clients are configured via the
245+
# configuration file is the log level given by this option honored.
246+
# log_level: :info
247+
248+
# Store BigDecimals as Decimal128s instead of strings in the db.
249+
# map_big_decimal_to_decimal128: true
250+
251+
# Preload all models in development, needed when models use inheritance.
252+
# preload_models: false
253+
254+
# When this flag is true, callbacks for every embedded document will be
255+
# called only once, even if the embedded document is embedded in multiple
256+
# documents in the root document's dependencies graph.
257+
# This is the default in 9.0. Setting this flag to false restores the
258+
# pre-9.0 behavior, where callbacks are called for every occurrence of an
259+
# embedded document. The pre-9.0 behavior leads to a problem that for multi
260+
# level nested documents callbacks are called multiple times.
261+
# See https://jira.mongodb.org/browse/MONGOID-5542
262+
# prevent_multiple_calls_of_embedded_callbacks: true
263+
264+
# Raise an error when performing a #find and the document is not found.
265+
# raise_not_found_error: true
266+
267+
# Raise an error when defining a scope with the same name as an
268+
# existing method.
269+
# scope_overwrite_exception: false
270+
271+
# Return stored times as UTC.
272+
# use_utc: false
273+
274+
# Configure Driver-specific options. (optional)
275+
driver_options:
276+
# When this flag is off, an aggregation done on a view will be executed over
277+
# the documents included in that view, instead of all documents in the
278+
# collection. When this flag is on, the view fiter is ignored.
279+
# broken_view_aggregate: true
280+
281+
# When this flag is set to false, the view options will be correctly
282+
# propagated to readable methods.
283+
# broken_view_options: true
284+
285+
# When this flag is set to true, the update and replace methods will
286+
# validate the paramters and raise an error if they are invalid.
287+
# validate_update_replace: false
288+
289+
290+
test:
291+
clients:
292+
default:
293+
database: app_test
294+
hosts:
295+
- localhost:27017
296+
options:
297+
read:
298+
mode: :primary
299+
max_pool_size: 1

0 commit comments

Comments
 (0)