From 8428da368d87bdf23fba15775f0145a65dfa966f Mon Sep 17 00:00:00 2001 From: Ido Shraga Date: Tue, 31 Aug 2021 16:49:33 +0300 Subject: [PATCH 1/5] add update operator to documentation --- docs/guide/querying.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/guide/querying.rst b/docs/guide/querying.rst index cf2024a0..e9e1de24 100644 --- a/docs/guide/querying.rst +++ b/docs/guide/querying.rst @@ -543,7 +543,10 @@ Documents may be updated atomically by using the There are several different "modifiers" that you may use with these methods: * ``set`` -- set a particular value +* ``set_on_insert`` -- set only if this is new document `need to add upsert=True`_ * ``unset`` -- delete a particular value (since MongoDB v1.3) +* ``max`` -- update only if value is bigger +* ``min`` -- update only if value is smaller * ``inc`` -- increment a value by a given amount * ``dec`` -- decrement a value by a given amount * ``push`` -- append a value to a list @@ -552,6 +555,7 @@ There are several different "modifiers" that you may use with these methods: * ``pull`` -- remove a value from a list * ``pull_all`` -- remove several values from a list * ``add_to_set`` -- add value to a list only if its not in the list already +* ``rename`` -- rename the key name .. _depending on the value: http://docs.mongodb.org/manual/reference/operator/update/pop/ From 7e10bb2894787341f7d028b12cee1f004ecdbc51 Mon Sep 17 00:00:00 2001 From: Ido Shraga Date: Wed, 1 Sep 2021 10:24:26 +0300 Subject: [PATCH 2/5] rename tester --- tests/queryset/test_queryset.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/queryset/test_queryset.py b/tests/queryset/test_queryset.py index 1aa4f32a..1a15a114 100644 --- a/tests/queryset/test_queryset.py +++ b/tests/queryset/test_queryset.py @@ -867,6 +867,23 @@ class TestQueryset(unittest.TestCase): assert "Bob" == bob.name assert 30 == bob.age + def test_rename(self): + self.Person.drop_collection() + self.Person.objects.create(name="Foo", age=11) + + bob = self.Person.objects.as_pymongo().first() + assert 'age' in bob + assert bob['age'] == 11 + + self.Person.objects(name="Foo").update( + rename__age='person_age' + ) + + bob = self.Person.objects.as_pymongo().first() + assert 'age' not in bob + assert 'person_age' in bob + assert bob['person_age'] == 11 + def test_save_and_only_on_fields_with_default(self): class Embed(EmbeddedDocument): field = IntField() From 85b0c1c945be672eac9dd84de9acffe8af5a783a Mon Sep 17 00:00:00 2001 From: idoshr <35264146+idoshr@users.noreply.github.com> Date: Mon, 20 Sep 2021 22:36:13 +0300 Subject: [PATCH 3/5] Update AUTHORS --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index a35fc5f1..60663940 100644 --- a/AUTHORS +++ b/AUTHORS @@ -262,3 +262,4 @@ that much better: * Jan Stein (https://github.com/janste63) * Timothé Perez (https://github.com/AchilleAsh) * oleksandr-l5 (https://github.com/oleksandr-l5) + * Ido Shraga (https://github.com/idoshr) From cb0035f87a7b0e609a127e28622084053f576828 Mon Sep 17 00:00:00 2001 From: Bastien Gerard Date: Thu, 30 Sep 2021 20:25:26 +0200 Subject: [PATCH 4/5] minor typo fix in docstring --- mongoengine/queryset/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mongoengine/queryset/base.py b/mongoengine/queryset/base.py index 5dc47e00..254e0fbf 100644 --- a/mongoengine/queryset/base.py +++ b/mongoengine/queryset/base.py @@ -720,7 +720,7 @@ class BaseQuerySet: return queryset.filter(pk=object_id).first() def in_bulk(self, object_ids): - """ "Retrieve a set of documents by their ids. + """Retrieve a set of documents by their ids. :param object_ids: a list or tuple of ObjectId's :rtype: dict of ObjectId's as keys and collection-specific From 28226f81a850966f270827016e8ab77fe9fe2112 Mon Sep 17 00:00:00 2001 From: Bastien Gerard Date: Thu, 30 Sep 2021 20:39:44 +0200 Subject: [PATCH 5/5] black it --- tests/queryset/test_queryset.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/tests/queryset/test_queryset.py b/tests/queryset/test_queryset.py index 1a15a114..5add0750 100644 --- a/tests/queryset/test_queryset.py +++ b/tests/queryset/test_queryset.py @@ -872,17 +872,15 @@ class TestQueryset(unittest.TestCase): self.Person.objects.create(name="Foo", age=11) bob = self.Person.objects.as_pymongo().first() - assert 'age' in bob - assert bob['age'] == 11 + assert "age" in bob + assert bob["age"] == 11 - self.Person.objects(name="Foo").update( - rename__age='person_age' - ) + self.Person.objects(name="Foo").update(rename__age="person_age") bob = self.Person.objects.as_pymongo().first() - assert 'age' not in bob - assert 'person_age' in bob - assert bob['person_age'] == 11 + assert "age" not in bob + assert "person_age" in bob + assert bob["person_age"] == 11 def test_save_and_only_on_fields_with_default(self): class Embed(EmbeddedDocument):