Skip to content

Commit 665f83d

Browse files
committed
Fixed #7
1 parent b86bdbb commit 665f83d

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

test/mongo/bulk_writes_test.exs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,34 @@ defmodule Mongo.BulkWritesTest do
114114

115115
end
116116

117+
test "create one small document and one large 16mb document", top do
118+
coll = unique_name()
119+
max_n = (16*1024*1024) - 44 # 44 bytes for 'key: "big" and v:'
120+
121+
122+
a_line_1k = Enum.reduce(1..1_024, "", fn _, acc -> acc <> "A" end)
123+
a_line_1m = Enum.reduce(1..1_024, "", fn _, acc -> acc <> a_line_1k end)
124+
a_line_16m = String.slice(Enum.reduce(1..16, "", fn _, acc -> acc <> a_line_1m end), 0..max_n)
125+
126+
b_line_1k = Enum.reduce(1..1_024, "", fn _, acc -> acc <> "B" end)
127+
b_line_1m = Enum.reduce(1..1_024, "", fn _, acc -> acc <> b_line_1k end)
128+
b_line_16m = String.slice(Enum.reduce(1..15, "", fn _, acc -> acc <> b_line_1m end), 0..max_n)
129+
130+
bulk = coll
131+
|> OrderedBulk.new()
132+
|> OrderedBulk.insert_one(%{v: a_line_1k, key: "small"})
133+
|> OrderedBulk.insert_one(%{v: a_line_16m, key: "big"})
134+
|> OrderedBulk.update_one(%{key: "small"}, %{"$set": %{v: b_line_1k}})
135+
|> OrderedBulk.update_one(%{key: "big"}, %{"$set": %{v: b_line_16m}})
136+
|> OrderedBulk.delete_one(%{key: "small"})
137+
|> OrderedBulk.delete_one(%{key: "big"})
138+
139+
%BulkWriteResult{} = result = BulkWrite.write(top.pid, bulk, w: 1)
140+
141+
assert %{:matched_count => 2, :deleted_count => 2, :modified_count => 2} == Map.take(result, [:matched_count, :deleted_count, :modified_count])
142+
assert {:ok, 0} == Mongo.count(top.pid, coll, %{})
143+
144+
end
145+
146+
117147
end

0 commit comments

Comments
 (0)