Skip to content

Commit

Permalink
merged changes from ajdavis:pymongo-3 branch
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Unsworth committed Jun 23, 2015
1 parent 801d7bf commit 5edbaef
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 35 deletions.
1 change: 0 additions & 1 deletion django_mongodb_engine/utils.py
Expand Up @@ -70,7 +70,6 @@ def log(self, op, duration, args, kwargs=None):
logger.debug(msg, extra={'duration': duration})

def find(self, *args, **kwargs):

return DebugCursor(self, self.collection, *args, **kwargs)

def logging_wrapper(method):
Expand Down
36 changes: 15 additions & 21 deletions docs/source/reference/settings.rst
Expand Up @@ -3,9 +3,9 @@ Settings

.. TODO fix highlighting
Connection Settings
Client Settings
-------------------
Additional flags may be passed to :class:`pymongo.Connection` using the
Additional flags may be passed to :class:`pymongo.MongoClient` using the
``OPTIONS`` dictionary::

DATABASES = {
Expand All @@ -14,27 +14,25 @@ Additional flags may be passed to :class:`pymongo.Connection` using the
'NAME' : 'my_database',
...
'OPTIONS' : {
'slave_okay' : True,
'tz_aware' : True,
'network_timeout' : 42,
'socketTimeoutMS' : 500,
...
}
}
}

All of these settings directly mirror PyMongo settings. In fact, all Django
MongoDB Engine does is lower-casing the names before passing the flags to
:class:`~pymongo.Connection`. For a list of possible options head over to the
`PyMongo documentation on connection options`_.
:class:`~pymongo.MongoClient`. For a list of possible options head over to the
`PyMongo documentation on client options`_.

.. _operations-setting:

Safe Operations (``getLastError``)
----------------------------------
Acknowledged Operations
-----------------------
Use the ``OPERATIONS`` dict to specify extra flags passed to
:meth:`Collection.save <pymongo.collection.Collection.save>`,
:meth:`~pymongo.collection.Collection.update` or
:meth:`~pymongo.collection.Collection.remove` (and thus to ``getLastError``):
:meth:`~pymongo.collection.Collection.remove` (and thus included in the write concern):

.. code-block:: python
Expand All @@ -43,21 +41,17 @@ Use the ``OPERATIONS`` dict to specify extra flags passed to
...
}
Since any options to ``getLastError`` imply ``safe=True``,
this configuration passes ``safe=True, w=3`` as keyword arguments to each of
:meth:`~pymongo.collection.Collection.save`,
:meth:`~pymongo.collection.Collection.update` and
:meth:`~pymongo.collection.Collection.remove`.
Get a more fine-grained setup by introducing another layer to this dict:

.. code-block:: python
'OPTIONS' : {
'OPERATIONS' : {
'save' : {'safe' : True},
'save' : {'w' : 3},
'update' : {},
'delete' : {'fsync' : True}
'delete' : {'j' : True}
},
...
}
Expand All @@ -69,10 +63,10 @@ Get a more fine-grained setup by introducing another layer to this dict:
"`insert vs. update`" into `save`.


A full list of ``getLastError`` flags may be found in the
`MongoDB documentation <http://www.mongodb.org/display/DOCS/getLastError+Command>`_.
A full list of write concern flags may be found in the
`MongoDB documentation <http://docs.mongodb.org/manual/core/write-concern/>`_.

.. _Similar to Django's built-in backends:
http://docs.djangoproject.com/en/dev/ref/settings/#std:setting-OPTIONS
.. _PyMongo documentation on connection options:
http://api.mongodb.org/python/current/api/pymongo/connection.html
.. _PyMongo documentation on client options:
http://api.mongodb.org/python/current/api/pymongo/mongo_client.html
28 changes: 15 additions & 13 deletions tests/mongodb/tests.py
Expand Up @@ -8,7 +8,7 @@
from django.db.models import Q
from encodings.big5 import codec
from gridfs import GridOut
from pymongo import ASCENDING, DESCENDING
from pymongo import ASCENDING, DESCENDING, ReadPreference, version_tuple as pymongo_version
from django_mongodb_engine.base import DatabaseWrapper
from models import *

Expand Down Expand Up @@ -204,20 +204,26 @@ def test_pymongo_connection_args(self):
class foodict(dict):
pass

tz_aware = True
document_class = foodict

with self.custom_database_wrapper({
'OPTIONS': {
'READ_PREFERENCE': ReadPreference.SECONDARY,
'TZ_AWARE': True,
'DOCUMENT_CLASS': foodict,
}}) as connection:
}}) as db:

connection = db.connection

codec_options = connection.connection.codec_options
if pymongo_version[0] >= 3:
tz_aware = connection.codec_options.tz_aware
document_class = connection.codec_options.document_class
else:
tz_aware = connection.tz_aware
document_class = connection.document_class

self.assertEqual(codec_options.tz_aware, tz_aware)
self.assertEqual(codec_options.document_class, document_class)
self.assertEqual(ReadPreference.SECONDARY, connection.read_preference)

self.assertEqual(True, tz_aware)
self.assertEqual(foodict, document_class)


def test_operation_flags(self):
Expand Down Expand Up @@ -254,11 +260,7 @@ def test_setup(flags, **method_kwargs):
test_setup({}, save={}, update={'multi': True}, remove={})
test_setup({}, save={}, update={'multi': True}, remove={})
test_setup({'delete': {}, 'update': {}}, save={}, update={'multi': True}, remove={})
test_setup({ 'insert': {'fsync': True}, 'delete': {'fsync': True}},

save={},
update={'multi': True},
remove={'fsync': True})
test_setup({ 'insert': {'fsync': True}, 'delete': {'fsync': True}}, save={}, update={'multi': True}, remove={'fsync': True})


def test_unique_safe(self):
Expand Down

0 comments on commit 5edbaef

Please sign in to comment.