Repository: MongoEngine/mongoengine

Issue:
I would like to report a bug on the update operation of dec or inc
hi, I recent find this stange behave of dec operation.

in the mong shell, there is no dec operation, only inc. the inc support number lower than 0.

``` javascript
db.things.update({}, {'$inc': {'order': 1}})
```

or

``` javascript
db.things.update({}, {'$inc': {'order': -1}})
```

both return ok, and run as expected.

the mongengine lib has both inc and dec operation.
the inc behave just like the mong shell inc.

``` python
t = Things.objects.first()
t.update(inc__order=1)
t.update(inc__order=-1)
```

both return ok, and run as expected.

the dec behave differentlly however.

``` python
t.update(dec__order=1)
t.update(dec__order=-1)
```

both return ok, but not run as expected. it seems the dec always run like:

``` python
t.update(inc__order: -1). 
```

that is very strange. and cause a bug cast me hours to fix it.



Discussion:
Which Python/MongoEngine/PyMongo version are you using?
Also next time, please format the code in your issue. Thanks.

the version is:

```
daipeng@dp-pc:~$ mongo --version
MongoDB shell version: 2.6.3
daipeng@dp-pc:~$ python --version
Python 2.7.3
daipeng@dp-pc:~$ pip freeze | grep pymongo
pymongo==2.7.1
daipeng@dp-pc:~$ pip freeze | grep mongoengine
mongoengine==0.8.7
```

and sorry for the code format. 

Well to me it seems that dec supports two different formats.
One with negative values and the second with positive values. Both of them correctly decrease the variable.
We should select one format and deprecate the other.
@MongoEngine/mongoengine What do you guys think?

Well as a user I would say that

```
t.update(inc__order=-1)
t.update(dec__order=1)
```

should be equivalent and

```
t.update(inc__order=1)
t.update(dec__order=-1)
```

should be equivalent and opposite to the previous.

I think that there should be one interface that abstracts away MongoDB's Idiosyncrasies.
It doesn't make sense to decrease using increase but you're right. It's a new feature.

Another thing to mention. There is only `$inc` operator in MongoDB, no `$dec`.

See http://docs.mongodb.org/manual/reference/operator/update/inc/#up._S_inc


Resolving patch:
diff --git a/mongoengine/queryset/transform.py b/mongoengine/queryset/transform.py
--- a/mongoengine/queryset/transform.py
+++ b/mongoengine/queryset/transform.py
@@ -233,8 +233,7 @@ def update(_doc_cls=None, **update):
                 # Support decrement by flipping a positive value's sign
                 # and using 'inc'
                 op = 'inc'
-                if value > 0:
-                    value = -value
+                value = -value
             elif op == 'add_to_set':
                 op = 'addToSet'
             elif op == 'set_on_insert':


Test patch:
diff --git a/tests/queryset/queryset.py b/tests/queryset/queryset.py
--- a/tests/queryset/queryset.py
+++ b/tests/queryset/queryset.py
@@ -1826,6 +1826,11 @@ class BlogPost(Document):
         post.reload()
         self.assertEqual(post.hits, 10)
 
+        # Negative dec operator is equal to a positive inc operator
+        BlogPost.objects.update_one(dec__hits=-1)
+        post.reload()
+        self.assertEqual(post.hits, 11)
+
         BlogPost.objects.update(push__tags='mongo')
         post.reload()
         self.assertTrue('mongo' in post.tags)