0

When I change document I see field new value. But sometimes I want to see its old value (or it would be correctly say, its current value). I know that I can see changed fields in _changed_fields attribute and something tells me that I can see the current value too. But I can't find where. And my searches gave no result.

What I want to notice: I want to find the solution for mongoengine, not for pymongo. Because I know that I can query document by pymongo and get the document, but it is an extra query to database and I would prefer not to bother db once more.

So, repeating the question above: how can I get current field value of a changed document in mongoengine?

egvo
  • 1,493
  • 18
  • 26

1 Answers1

0

As I mentioned in question there is a solution with pymongo:

user = User.objects.with_id(some_id)
user.email = 'test@mail.ru'
# And then somewhere below I want to see an old value
# For example, I want 'email' field
user_coll = User._get_collection()
user_data = user_coll.find_one({'_id': user}, {'_id': 0, 'email': 1})
old_value = user_data.get('email', '')

But there was an extra query to database. And because of it I want to find solution with mongoengine.

egvo
  • 1,493
  • 18
  • 26