Skip to content

Commit 5604156

Browse files
committed
PYTHON-2023 Use $merge to non-admin db to fix db.aggregate write concern test
1 parent bb18da7 commit 5604156

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

test/test_database.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,20 +1036,28 @@ def test_database_aggregation(self):
10361036
@client_context.require_version_min(3, 6, 0)
10371037
@client_context.require_no_mongos
10381038
def test_database_aggregation_fake_cursor(self):
1039-
admin = self.admin.with_options(write_concern=WriteConcern(w=0))
1040-
test_collection_name = "test_output"
1041-
admin.drop_collection(test_collection_name)
1042-
self.addCleanup(admin.drop_collection, test_collection_name)
1039+
coll_name = "test_output"
1040+
if client_context.version < (4, 3):
1041+
db_name = "admin"
1042+
write_stage = {"$out": coll_name}
1043+
else:
1044+
# SERVER-43287 disallows writing with $out to the admin db, use
1045+
# $merge instead.
1046+
db_name = "pymongo_test"
1047+
write_stage = {
1048+
"$merge": {"into": {"db": db_name, "coll": coll_name}}}
1049+
output_coll = self.client[db_name][coll_name]
1050+
output_coll.drop()
1051+
self.addCleanup(output_coll.drop)
10431052

1053+
admin = self.admin.with_options(write_concern=WriteConcern(w=0))
10441054
pipeline = self.pipeline[:]
1045-
pipeline.append({"$out": "test_output"})
1055+
pipeline.append(write_stage)
10461056
with admin.aggregate(pipeline) as cursor:
10471057
with self.assertRaises(StopIteration):
10481058
next(cursor)
10491059

1050-
result = wait_until(
1051-
admin[test_collection_name].find_one,
1052-
"read unacknowledged write")
1060+
result = wait_until(output_coll.find_one, "read unacknowledged write")
10531061
self.assertEqual(result["dummy"], self.result["dummy"])
10541062

10551063
@client_context.require_version_max(3, 6, 0, -1)

0 commit comments

Comments
 (0)