Skip to content

Commit c05e895

Browse files
committed
JB feedback
1 parent f73eaf6 commit c05e895

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

source/includes/read/retrieve.rb

+4-8
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,21 @@
77

88
uri = '<connection string>'
99

10-
begin
11-
client = Mongo::Client.new(uri)
12-
10+
Mongo::Client.new(uri) do |client|
1311
# start-db-coll
1412
database = client.use('sample_training')
1513
collection = database[:companies]
1614
# end-db-coll
1715

1816
# Finds one document with a "name" value of "LinkedIn"
1917
# start-find-one
20-
document = collection.find({ 'name' => 'LinkedIn' }).first
18+
document = collection.find(name: 'LinkedIn').first
2119
puts document
2220
# end-find-one
2321

2422
# Finds documents with a "founded_year" value of 1970
2523
# start-find-many
26-
results = collection.find({ 'founded_year' => 1970 })
24+
results = collection.find(founded_year: 1970)
2725
# end-find-many
2826

2927
# start-cursor
@@ -35,13 +33,11 @@
3533

3634
# Finds and prints up to 2 documents with a "number_of_employees" value of 1000
3735
# start-modify
38-
limit_results = collection.find({ 'number_of_employees' => 1000 }).limit(2)
36+
limit_results = collection.find(number_of_employees: 1000).limit(2)
3937

4038
limit_results.each do |doc|
4139
puts doc
4240
end
4341
# end-modify
44-
ensure
45-
client&.close
4642
end
4743

source/read.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Read Data from MongoDB
1515
:values: reference
1616

1717
.. meta::
18-
:description: Learn how to use the Ruby driver to read data to MongoDB.
18+
:description: Learn how to use the Ruby driver to read data from MongoDB.
1919
:keywords: usage examples, save, crud, read, code example
2020

2121
.. toctree::

0 commit comments

Comments
 (0)