@@ -85,6 +85,51 @@ On MongoDB 2.4, an exception is only raised if the insert fails and the
8585 ])
8686 result.inserted_count # returns 2, because 2 documents were inserted.
8787
88+ .. _specify-decimal128:
89+
90+ Specify a ``Decimal128`` number
91+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
92+
93+ .. versionadded:: 3.4
94+
95+ :manual:`Decimal128</tutorial/model-monetary-data>` is a
96+ :doc:`BSON datatype </bson-tutorials>`
97+ that employs 128-bit decimal-based floating-point values capable
98+ of emulating decimal rounding with exact precision. This
99+ functionality is intended for applications that handle
100+ :manual:`monetary data </tutorial/model-monetary-data>`,
101+ such as financial and tax computations.
102+
103+ The following example inserts a value of type ``Decimal128`` into
104+ the ``price`` field of a collection named ``inventory``:
105+
106+ .. code-block:: ruby
107+
108+ client = Mongo::Client.new([ '127.0.0.1:27017' ], :database => 'test')
109+
110+ price = BSON::Decimal128.new("428.79")
111+ client[:inventory].insert_one({ "_id" => 1,
112+ "item" => "26 inch monitor",
113+ "price" => price })
114+
115+ The above operation produces the following document:
116+
117+ .. code-block:: javascript
118+
119+ { "_id" : 1, "item" : "26 inch monitor", "price" : NumberDecimal("428.79") }
120+
121+ You can also create a ``Decimal128`` object from a Ruby ``BigDecimal``
122+ object, or with ``Decimal128.from_string()``.
123+
124+ .. code-block:: ruby
125+
126+ big_decimal = BigDecimal.new(428.79, 5)
127+ price = BSON::Decimal128.new(big_decimal)
128+ # => BSON::Decimal128('428.79')
129+
130+ price = BSON::Decimal128.from_string("428.79")
131+ # => BSON::Decimal128('428.79')
132+
88133Reading
89134-------
90135
@@ -110,7 +155,7 @@ query:
110155.. _ruby-driver-query-options:
111156
112157Query Options
113- `````````````
158+ ~~~~~~~~~~~~~
114159
115160To add options to a query, chain the appropriate methods after the
116161``find`` method. Note that the underlying object, the ``Mongo::Collection::View``,
@@ -182,7 +227,7 @@ when querying and their corresponding methods as examples.
182227 client[:artists].find.sort(:name => -1)
183228
184229Additional Query Operations
185- ```````````````````````````
230+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
186231
187232``count``
188233 Get the total number of documents an operation returns.
@@ -204,7 +249,7 @@ Additional Query Operations
204249 client[:artists].find.distinct(:name )
205250
206251Tailable Cursors
207- ````````````````
252+ ~~~~~~~~~~~~~~~~
208253
209254For capped collections you may use a :manual:`tailable cursor
210255</core/tailable-cursors/>` that remains open
@@ -233,7 +278,7 @@ following code example shows how a tailable cursor might be used:
233278.. _ruby-driver-read-preference:
234279
235280Read Preference
236- ````````````````
281+ ~~~~~~~~~~~~~~~
237282
238283Read preference determines the candidate :manual:`replica set</replication/>`
239284members to which a query or command can be sent. They consist of a **mode** specified as
@@ -270,15 +315,15 @@ option when a command is run on a database.
270315 tag_sets: [ { 'dc' => 'nyc' } ] } )
271316
272317Mode
273- ````
318+ ~~~~
274319
275320There are five possible read preference modes. They are ``:primary``,
276321``:secondary``, ``:primary_preferred``, ``:secondary_preferred``,
277322``:nearest``. Please see the :manual:`read preference documentation in the MongoDB Manual
278323</core/read-preference/>` for an explanation of the modes and tag sets.
279324
280325Tag sets
281- ````````
326+ ~~~~~~~~
282327
283328The ``tag_sets`` parameter is an ordered list of tag sets used to
284329restrict the eligibility of servers for selection, such as for data
0 commit comments