|
15 | 15 | context "Snapshot Query Example 1" do
|
16 | 16 | before do
|
17 | 17 | client = Mongo::Client.new(uri_string, database: "pets")
|
18 |
| - client['cats'].delete_many({}) |
19 |
| - client['dogs'].delete_many({}) |
| 18 | + client['cats'].delete_many |
| 19 | + client['dogs'].delete_many |
20 | 20 |
|
21 |
| - client['cats'].insert_one({ |
| 21 | + client['cats'].insert_one( |
22 | 22 | name: "Whiskers",
|
23 | 23 | color: "white",
|
24 | 24 | age: 10,
|
25 | 25 | adoptable: true
|
26 |
| - }) |
| 26 | + ) |
27 | 27 |
|
28 |
| - client['dogs'].insert_one({ |
| 28 | + client['dogs'].insert_one( |
29 | 29 | name: "Pebbles",
|
30 | 30 | color: "Brown",
|
31 | 31 | age: 10,
|
32 | 32 | adoptable: true
|
33 |
| - }) |
| 33 | + ) |
34 | 34 | client.close
|
35 | 35 | end
|
36 | 36 |
|
37 | 37 | it "returns a snapshot of the data" do
|
38 | 38 |
|
39 |
| - adoptablePetsCount = 0 |
| 39 | + adoptable_pets_count = 0 |
40 | 40 |
|
41 | 41 | # Start Snapshot Query Example 1
|
42 | 42 |
|
43 | 43 | client = Mongo::Client.new(uri_string, database: "pets")
|
44 | 44 |
|
45 | 45 | client.start_session(snapshot: true) do |session|
|
46 |
| - adoptablePetsCount = client['cats'].aggregate([ |
| 46 | + adoptable_pets_count = client['cats'].aggregate([ |
47 | 47 | { "$match": { "adoptable": true } },
|
48 |
| - { "$count": "adoptableCatsCount" } |
49 |
| - ], session: session).first["adoptableCatsCount"] |
| 48 | + { "$count": "adoptable_cats_count" } |
| 49 | + ], session: session).first["adoptable_cats_count"] |
50 | 50 |
|
51 |
| - adoptablePetsCount += client['dogs'].aggregate([ |
| 51 | + adoptable_pets_count += client['dogs'].aggregate([ |
52 | 52 | { "$match": { "adoptable": true } },
|
53 |
| - { "$count": "adoptableDogsCount" } |
54 |
| - ], session: session).first["adoptableDogsCount"] |
| 53 | + { "$count": "adoptable_dogs_count" } |
| 54 | + ], session: session).first["adoptable_dogs_count"] |
55 | 55 |
|
56 |
| - puts adoptablePetsCount |
| 56 | + puts adoptable_pets_count |
57 | 57 | end
|
58 | 58 |
|
59 | 59 | # End Snapshot Query Example 1
|
60 | 60 |
|
61 |
| - expect(adoptablePetsCount).to eq 2 |
| 61 | + expect(adoptable_pets_count).to eq 2 |
62 | 62 | client.close
|
63 | 63 | end
|
64 | 64 | end
|
65 | 65 |
|
66 | 66 | context "Snapshot Query Example 2" do
|
67 | 67 | before do
|
68 | 68 | client = Mongo::Client.new(uri_string, database: "retail")
|
69 |
| - client['sales'].delete_many({}) |
| 69 | + client['sales'].delete_many |
70 | 70 |
|
71 |
| - client['sales'].insert_one({ |
| 71 | + client['sales'].insert_one( |
72 | 72 | shoeType: "boot",
|
73 | 73 | price: 30,
|
74 | 74 | saleDate: Time.now
|
75 |
| - }) |
| 75 | + ) |
76 | 76 | client.close
|
77 | 77 | end
|
78 | 78 |
|
|
102 | 102 | }
|
103 | 103 | }
|
104 | 104 | },
|
105 |
| - { "$count": "totalDailySales" } |
106 |
| - ], session: session).first["totalDailySales"] |
| 105 | + { "$count": "total_daily_sales" } |
| 106 | + ], session: session).first["total_daily_sales"] |
107 | 107 | end
|
108 | 108 |
|
109 | 109 | # End Snapshot Query Example 2
|
|
0 commit comments