Skip to content

Commit 5edbaef

Browse files
author
Mark Unsworth
committed
merged changes from ajdavis:pymongo-3 branch
1 parent 801d7bf commit 5edbaef

File tree

3 files changed

+30
-35
lines changed

3 files changed

+30
-35
lines changed

django_mongodb_engine/utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ def log(self, op, duration, args, kwargs=None):
7070
logger.debug(msg, extra={'duration': duration})
7171

7272
def find(self, *args, **kwargs):
73-
7473
return DebugCursor(self, self.collection, *args, **kwargs)
7574

7675
def logging_wrapper(method):

docs/source/reference/settings.rst

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ Settings
33

44
.. TODO fix highlighting
55
6-
Connection Settings
6+
Client Settings
77
-------------------
8-
Additional flags may be passed to :class:`pymongo.Connection` using the
8+
Additional flags may be passed to :class:`pymongo.MongoClient` using the
99
``OPTIONS`` dictionary::
1010

1111
DATABASES = {
@@ -14,27 +14,25 @@ Additional flags may be passed to :class:`pymongo.Connection` using the
1414
'NAME' : 'my_database',
1515
...
1616
'OPTIONS' : {
17-
'slave_okay' : True,
18-
'tz_aware' : True,
19-
'network_timeout' : 42,
17+
'socketTimeoutMS' : 500,
2018
...
2119
}
2220
}
2321
}
2422

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

3028
.. _operations-setting:
3129

32-
Safe Operations (``getLastError``)
33-
----------------------------------
30+
Acknowledged Operations
31+
-----------------------
3432
Use the ``OPERATIONS`` dict to specify extra flags passed to
3533
:meth:`Collection.save <pymongo.collection.Collection.save>`,
3634
:meth:`~pymongo.collection.Collection.update` or
37-
:meth:`~pymongo.collection.Collection.remove` (and thus to ``getLastError``):
35+
:meth:`~pymongo.collection.Collection.remove` (and thus included in the write concern):
3836

3937
.. code-block:: python
4038
@@ -43,21 +41,17 @@ Use the ``OPERATIONS`` dict to specify extra flags passed to
4341
...
4442
}
4543
46-
Since any options to ``getLastError`` imply ``safe=True``,
47-
this configuration passes ``safe=True, w=3`` as keyword arguments to each of
48-
:meth:`~pymongo.collection.Collection.save`,
49-
:meth:`~pymongo.collection.Collection.update` and
50-
:meth:`~pymongo.collection.Collection.remove`.
44+
5145
5246
Get a more fine-grained setup by introducing another layer to this dict:
5347

5448
.. code-block:: python
5549
5650
'OPTIONS' : {
5751
'OPERATIONS' : {
58-
'save' : {'safe' : True},
52+
'save' : {'w' : 3},
5953
'update' : {},
60-
'delete' : {'fsync' : True}
54+
'delete' : {'j' : True}
6155
},
6256
...
6357
}
@@ -69,10 +63,10 @@ Get a more fine-grained setup by introducing another layer to this dict:
6963
"`insert vs. update`" into `save`.
7064

7165

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

7569
.. _Similar to Django's built-in backends:
7670
http://docs.djangoproject.com/en/dev/ref/settings/#std:setting-OPTIONS
77-
.. _PyMongo documentation on connection options:
78-
http://api.mongodb.org/python/current/api/pymongo/connection.html
71+
.. _PyMongo documentation on client options:
72+
http://api.mongodb.org/python/current/api/pymongo/mongo_client.html

tests/mongodb/tests.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from django.db.models import Q
99
from encodings.big5 import codec
1010
from gridfs import GridOut
11-
from pymongo import ASCENDING, DESCENDING
11+
from pymongo import ASCENDING, DESCENDING, ReadPreference, version_tuple as pymongo_version
1212
from django_mongodb_engine.base import DatabaseWrapper
1313
from models import *
1414

@@ -204,20 +204,26 @@ def test_pymongo_connection_args(self):
204204
class foodict(dict):
205205
pass
206206

207-
tz_aware = True
208-
document_class = foodict
209-
210207
with self.custom_database_wrapper({
211208
'OPTIONS': {
209+
'READ_PREFERENCE': ReadPreference.SECONDARY,
212210
'TZ_AWARE': True,
213211
'DOCUMENT_CLASS': foodict,
214-
}}) as connection:
212+
}}) as db:
213+
214+
connection = db.connection
215215

216-
codec_options = connection.connection.codec_options
216+
if pymongo_version[0] >= 3:
217+
tz_aware = connection.codec_options.tz_aware
218+
document_class = connection.codec_options.document_class
219+
else:
220+
tz_aware = connection.tz_aware
221+
document_class = connection.document_class
217222

218-
self.assertEqual(codec_options.tz_aware, tz_aware)
219-
self.assertEqual(codec_options.document_class, document_class)
223+
self.assertEqual(ReadPreference.SECONDARY, connection.read_preference)
220224

225+
self.assertEqual(True, tz_aware)
226+
self.assertEqual(foodict, document_class)
221227

222228

223229
def test_operation_flags(self):
@@ -254,11 +260,7 @@ def test_setup(flags, **method_kwargs):
254260
test_setup({}, save={}, update={'multi': True}, remove={})
255261
test_setup({}, save={}, update={'multi': True}, remove={})
256262
test_setup({'delete': {}, 'update': {}}, save={}, update={'multi': True}, remove={})
257-
test_setup({ 'insert': {'fsync': True}, 'delete': {'fsync': True}},
258-
259-
save={},
260-
update={'multi': True},
261-
remove={'fsync': True})
263+
test_setup({ 'insert': {'fsync': True}, 'delete': {'fsync': True}}, save={}, update={'multi': True}, remove={'fsync': True})
262264

263265

264266
def test_unique_safe(self):

0 commit comments

Comments
 (0)