From 1eae97731f2a384cb7b27404aa9b59741155f7bc Mon Sep 17 00:00:00 2001 From: Erdenezul Date: Wed, 30 Aug 2017 12:04:04 +0800 Subject: [PATCH] Fix Document.modify fail on sharded collection #1569 --- mongoengine/document.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mongoengine/document.py b/mongoengine/document.py index f1622934..71929cf1 100644 --- a/mongoengine/document.py +++ b/mongoengine/document.py @@ -280,6 +280,9 @@ class Document(BaseDocument): elif query[id_field] != self.pk: raise InvalidQueryError('Invalid document modify query: it must modify only this document.') + # Need to add shard key to query, or you get an error + query.update(self._object_key) + updated = self._qs(**query).modify(new=True, **update) if updated is None: return False