bug fix: set function mongodb used for updates

This commit is contained in:
Steve Nyemba 2024-04-16 09:42:33 -05:00
parent e1763b1b19
commit f6919ccd93
1 changed files with 9 additions and 4 deletions

View File

@ -12,7 +12,8 @@ from bson.binary import Binary
from datetime import datetime from datetime import datetime
import pandas as pd import pandas as pd
import numpy as np import numpy as np
import gridfs # import gridfs
from gridfs import GridFS
import sys import sys
import json import json
import re import re
@ -243,13 +244,17 @@ class Writer(Mongo):
""" """
collection = self.db[self.collection] collection = self.db[self.collection]
if collection.count_document() > 0 and '_id' in document: if collection.count_documents() > 0 and '_id' in document:
id = document['_id'] id = document['_id']
del document['_id'] del document['_id']
collection.find_one_and_replace({'_id':id},document) collection.find_one_and_replace({'_id':id},document)
else: else:
collection.delete_many({}) #
self.write(info) # Nothing to be done if we did not find anything
#
pass
# collection.delete_many({})
# self.write(info)
def close(self): def close(self):
Mongo.close(self) Mongo.close(self)
# collecton.update_one({"_id":self.collection},document,True) # collecton.update_one({"_id":self.collection},document,True)