Skip to content

Commit

Permalink
Fix a bug in mongoreader preventing using existing collections
Browse files Browse the repository at this point in the history
  • Loading branch information
DennisKrone committed Feb 5, 2024
1 parent ea7d3ac commit 2587e35
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions locust_plugins/mongoreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ def __init__(
"""
self.timestamp_field = timestamp_field
self.coll: Collection = (
coll or MongoClient(env["LOCUST_MONGO"])[env["LOCUST_MONGO_DATABASE"]][env["LOCUST_MONGO_COLLECTION"]]
)
if not coll:
self.coll: Collection = MongoClient(env["LOCUST_MONGO"])[env["LOCUST_MONGO_DATABASE"]][env["LOCUST_MONGO_COLLECTION"]]
else:
self.coll = coll
self.cursor: Cursor = self.coll.find(filter, sort=[(self.timestamp_field, 1)])
records_in_buffer = self.cursor._refresh() # trigger fetch immediately instead of waiting for the first next()
if not records_in_buffer:
Expand Down

0 comments on commit 2587e35

Please sign in to comment.