Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrating to PyMongo 4 + Fixes #125

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions flask_profiler/storage/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(self, config=None):
self.collection_name = self.config.get("COLLECTION", "measurements")

def createIndex():
self.collection.ensure_index(
self.collection.create_index(
[
('startedAt', 1),
('endedAt', 1),
Expand Down Expand Up @@ -86,19 +86,19 @@ def insert(self, measurement):
measurement["endedAt"] = datetime.datetime.fromtimestamp(
measurement["endedAt"])

result = self.collection.insert(measurement)
result = self.collection.insert_one(measurement)
if result:
return True
return False

def truncate(self):
result = self.collection.remove()
result = self.collection.delete_many({})
if result:
return True
return False

def delete(self, measurementId):
result = self.collection.remove({"_id": ObjectId(measurementId)})
result = self.collection.delete_one({"_id": ObjectId(measurementId)})
if result:
return True
return False
Expand Down Expand Up @@ -248,7 +248,7 @@ def clearify(self, obj):
available_types = [int, dict, str, list]
obj["startedAt"] = obj["startedAt"].strftime("%s")
obj["endedAt"] = obj["endedAt"].strftime("%s")
for k, v in obj.items():
for k, v in list(obj.items()):
if any([isinstance(v, av_type) for av_type in available_types]):
continue
if k == "_id":
Expand Down