Skip to content

Commit 706bcc8

Browse files
authored
RUBY-2165 added documentation to Create Client to explain block syntax (#1974)
* RUBY-2165 added documentation for block syntax * RUBY-2165 fixed some typos
1 parent 8544d85 commit 706bcc8

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

source/tutorials/ruby-driver-create-client.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,18 @@ specify the Atlas deployment URI:
4848
The driver will discover all nodes in the cluster and connect to them as
4949
needed.
5050

51+
Block Syntax
52+
````````````
53+
54+
Another way to create a Mongo::Client object is to use the block syntax:
55+
56+
.. code-block:: ruby
57+
58+
Mongo::Client.new(...) do |client|
59+
# work with the client
60+
end
61+
62+
Note that when creating a client using this syntax, the client is automatically closed after the block finishes executing.
5163

5264
Database
5365
````````
@@ -1064,6 +1076,8 @@ When ``#close`` is called on a client by any thread, all connections are closed:
10641076

10651077
client.close
10661078

1079+
Note that when creating a client using the `block syntax <#block-syntax>`_ described above, the client is automatically closed after the block finishes executing.
1080+
10671081

10681082
Usage with Forking Servers
10691083
==========================

0 commit comments

Comments
 (0)