Skip to content

Commit 7e3fdf8

Browse files
committed
feedback
1 parent ed2bf52 commit 7e3fdf8

File tree

1 file changed

+72
-81
lines changed

1 file changed

+72
-81
lines changed

source/read/databases-collection.rb

Lines changed: 72 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -8,98 +8,89 @@
88
uri = '<connection string>'
99

1010
Mongo::Client.new(uri) do |client|
11-
# start-access-db
12-
client = Mongo::Client.new(['127.0.0.1:27017'], database: 'test_database')
13-
database = client.database
14-
# end-access-db
11+
# start-access-db
12+
client = Mongo::Client.new(['127.0.0.1:27017'], database: 'test_database')
13+
database = client.database
14+
# end-access-db
1515

16-
# start-access-cl
17-
client = Mongo::Client.new(['127.0.0.1:27017'], database: 'test_database')
18-
database = client.database
19-
collection = database['test_collection']
20-
# end-access-cl
16+
# start-access-cl
17+
database = client.database
18+
collection = database['test_collection']
19+
# end-access-cl
2120

22-
# start-create-collection
23-
client = Mongo::Client.new(['127.0.0.1:27017'], database: 'test_database')
24-
database = client.database
25-
26-
database.command(create: 'example_collection', capped: true, size: 1024)
27-
# end-create-collection
21+
# start-create-collection
22+
database = client.database
2823

29-
# start-get-list
30-
client = Mongo::Client.new(['IP_ADDRESS_001:27017'], database: 'test_database')
31-
database = client.database
24+
database.command(create: 'example_collection', capped: true, size: 1024)
25+
# end-create-collection
26+
27+
# start-get-list
28+
database = client.database
3229

33-
collection_list = database.collections
30+
collection_list = database.collections
3431

35-
collection_list.each do |collection|
36-
puts collection.name
37-
end
38-
# end-get-list
32+
collection_list.each do |collection|
33+
puts collection.name
34+
end
35+
# end-get-list
3936

40-
# start-get-list-names
41-
client = Mongo::Client.new(['IP_ADDRESS_001:27017'], database: 'test_database')
42-
database = client.database
37+
# start-get-list-names
38+
database = client.database
4339

44-
collection_names = database.collection_names
40+
collection_names = database.collection_names
4541

46-
collection_names.each do |name|
47-
puts name
48-
end
49-
# end-get-list-names
42+
collection_names.each do |name|
43+
puts name
44+
end
45+
# end-get-list-names
5046

51-
# start-delete
52-
client = Mongo::Client.new(['127.0.0.1:27017'], database: 'test_database')
53-
database = client.database
47+
# start-delete
48+
database = client.database
5449

55-
collection = database[:test_collection]
56-
collection.drop
57-
# end-delete
58-
59-
# start-with-database
60-
client = Mongo::Client.new(['IP_ADDRESS_001:27017'], database: 'test_database')
61-
62-
database_with_settings = client.use('test_database').with(
63-
read: { mode: :secondary },
64-
read_concern: { level: :local },
65-
write: { w: :majority }
66-
)
67-
# end-with-database
68-
69-
# start-with-collection
70-
client = Mongo::Client.new(['IP_ADDRESS_001:27017'], database: 'test_database')
71-
72-
collection_with_settings = client[:test_collection].with(
73-
read: { mode: :secondary },
74-
read_concern: { level: :local },
75-
write: { w: :majority }
76-
)
77-
# end-with-collection
78-
79-
# start-tag-sets
80-
client = Mongo::Client.new(['IP_ADDRESS_001:27017'], database: 'test', read: {
81-
mode: :secondary,
82-
tag_sets: [{'dc' => 'ny'}, {'dc' => 'sf'}]
83-
})
50+
collection = database[:test_collection]
51+
collection.drop
52+
# end-delete
53+
54+
# start-with-database
55+
database_with_settings = client.use('test_database').with(
56+
read: { mode: :secondary },
57+
read_concern: { level: :local },
58+
write: { w: :majority }
59+
)
60+
# end-with-database
61+
62+
# start-with-collection
63+
64+
collection_with_settings = client[:test_collection].with(
65+
read: { mode: :secondary },
66+
read_concern: { level: :local },
67+
write: { w: :majority }
68+
)
69+
# end-with-collection
70+
71+
# start-tag-sets
72+
client = Mongo::Client.new(['IP_ADDRESS_001:27017'], database: 'test', read: {
73+
mode: :secondary,
74+
tag_sets: [{'dc' => 'ny'}, {'dc' => 'sf'}]
75+
})
8476

85-
database = client.database
77+
database = client.database
8678

87-
collection = database[:example_collection]
88-
# end-tag-sets
89-
90-
91-
# start-local-threshold-example
92-
client = Mongo::Client.new(
93-
['IP_ADDRESS_001:27017'],
94-
database: 'test_database',
95-
read: { mode: :secondary_preferred },
96-
local_threshold: 35
97-
)
98-
99-
database = client.database
79+
collection = database[:example_collection]
80+
# end-tag-sets
81+
82+
# start-local-threshold-example
83+
client = Mongo::Client.new(
84+
['IP_ADDRESS_001:27017'],
85+
database: 'test_database',
86+
read: { mode: :secondary_preferred },
87+
local_threshold: 35
88+
)
10089

101-
collection = database[:example_collection]
102-
result = collection.find({}).first
103-
puts result
104-
# end-local-threshold-example
90+
database = client.database
10591

92+
collection = database[:example_collection]
93+
result = collection.find({}).first
94+
puts result
95+
# end-local-threshold-example
96+
end

0 commit comments

Comments
 (0)