How to update updated time field in MongoDB only if document other fields got changed in single query

Viewed 365

How to do this in a single mongo query (we should not update the updated field always, only update if other fields got modified)

write_results_obj = db[collection].update_one(query, {update_key: record}, upsert=upsert)
if write_results_obj.modified_count > 0:
    db[collection].update_one(query, {updated: datetime.utcnow()})

0 Answers
Related