File tree Expand file tree Collapse file tree 2 files changed +9
-14
lines changed
Expand file tree Collapse file tree 2 files changed +9
-14
lines changed Original file line number Diff line number Diff line change 66
77uri = "<connection string URI>"
88
9- begin
10- client = Mongo ::Client . new ( uri )
11-
9+ Mongo ::Client . new ( uri ) do |client |
1210 # start-db-coll
1311 database = client . use ( 'sample_restaurants' )
1412 collection = database [ :restaurants ]
1513 # end-db-coll
1614
1715 # Updates a single document
1816 # start-update-one
19- filter = { ' name' => 'Happy Garden' }
17+ filter = { name : 'Happy Garden' }
2018
21- update = { '$set' => { ' name' => 'Mountain House' } }
19+ update = { '$set' => { name : 'Mountain House' } }
2220
2321 single_result = collection . update_one ( filter , update )
2422
2725
2826 # Updates multiple documents
2927 # start-update-many
30- filter = { ' name' => 'Starbucks' }
28+ filter = { name : 'Starbucks' }
3129
32- update = { '$rename' => { ' address' => 'location' } }
30+ update = { '$rename' => { address : 'location' } }
3331
3432 many_result = collection . update_many ( filter , update )
3533
4038 # start-update-options
4139 filter = { 'name' => 'Sunrise Pizzeria' }
4240
43- update = { '$set' => { ' borough' => 'Queens' , ' cuisine' => 'Italian' } }
41+ update = { '$set' => { borough : 'Queens' , cuisine : 'Italian' } }
4442
4543 upsert_result = collection . update_one ( filter , update , upsert : true )
4644
4745 puts "#{ upsert_result . modified_count } document(s) updated."
4846 # end-update-options
49-
50- ensure
51- client &.close
5247end
Original file line number Diff line number Diff line change @@ -140,7 +140,7 @@ configure the update operation:
140140 | Default: ``false``
141141
142142 * - ``collation``
143- - | The kind of language collation to use when sorting
143+ - | Language collation to use when sorting
144144 results. For more information, see :manual:`Collation </reference/collation/#std-label-collation>`
145145 in the {+mdb-server+} manual.
146146
@@ -154,7 +154,7 @@ configure the update operation:
154154 in the {+mdb-server+} manual.
155155
156156 * - ``let``
157- - | A map of parameter names and values to set top-level
157+ - | Map of parameter names and values to set top-level
158158 variables for the operation. Values must be constant or closed
159159 expressions that don't reference document fields. For more information,
160160 see the :manual:`let statement
@@ -171,7 +171,7 @@ operator to set the ``borough`` field value in the first matching document to
171171
172172Because the ``upsert`` option is set to ``true``, if the query filter
173173doesn't match any existing documents, the driver inserts a new document that
174- has the fields and values in the filter and update documents.
174+ contains the fields and values in the filter and update documents.
175175
176176.. io-code-block::
177177 :copyable: true
You can’t perform that action at this time.
0 commit comments