Skip to content

Commit

Permalink
Really fix the save command
Browse files Browse the repository at this point in the history
Use `insert` instead of `replace` in the case where the document does not have
an `_id` field
  • Loading branch information
shankari committed Mar 10, 2020
1 parent 78c0908 commit 295d9ae
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions emission/core/get_database.py
Expand Up @@ -264,6 +264,8 @@ def get_fake_sections_db():
# https://github.com/e-mission/e-mission-server/issues/533#issuecomment-349430623
def save(db, entry):
if '_id' in entry:
db.replace_one({'_id': entry['_id']}, entry, upsert=True)
result = db.replace_one({'_id': entry['_id']}, entry, upsert=True)
# logging.debug("entry has id, calling with match, result = %s" % result.raw_result)
else:
db.replace_one({}, entry, upsert=True)
result = db.insert_one(entry)
# logging.debug("entry has id, calling without match, result = %s" % result.inserted_id)

0 comments on commit 295d9ae

Please sign in to comment.