From 74a3c4451bcb00f7cf7797ea2de792f87a2e629b Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Fri, 27 Jun 2014 16:35:26 +0300 Subject: [PATCH 01/13] using() was added in 0.9. Not 0.8. --- 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 4b7ec491..99ce6fef 100644 --- a/mongoengine/queryset/base.py +++ b/mongoengine/queryset/base.py @@ -601,7 +601,7 @@ class BaseQuerySet(object): :param alias: The database alias - .. versionadded:: 0.8 + .. versionadded:: 0.9 """ with switch_db(self._document, alias) as cls: From cfbb283f85408115c61146039b17110560232d6f Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Fri, 27 Jun 2014 16:48:38 +0300 Subject: [PATCH 02/13] Added Django 1.7RC1 to the build process and excluded it from running on Python 2.6. --- .travis.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 40736165..9a076fdc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,19 +9,27 @@ python: - "3.4" - "pypy" env: + - PYMONGO=dev DJANGO=dev - PYMONGO=dev DJANGO=1.6.5 - PYMONGO=dev DJANGO=1.5.8 + - PYMONGO=2.7.1 DJANGO=dev - PYMONGO=2.7.1 DJANGO=1.6.5 - PYMONGO=2.7.1 DJANGO=1.5.8 matrix: + exclude: + - python: "2.6" + env: PYMONGO=dev DJANGO=dev + - python: "2.6" + env: PYMONGO=2.7.1 DJANGO=dev fast_finish: true install: - sudo apt-get install python-dev python3-dev libopenjpeg-dev zlib1g-dev libjpeg-turbo8-dev libtiff4-dev libjpeg8-dev libfreetype6-dev liblcms2-dev libwebp-dev tcl8.5-dev tk8.5-dev python-tk - if [[ $PYMONGO == 'dev' ]]; then pip install https://github.com/mongodb/mongo-python-driver/tarball/master; true; fi - if [[ $PYMONGO != 'dev' ]]; then pip install pymongo==$PYMONGO; true; fi - - pip install Django==$DJANGO + - [[ $DJANGO == 'dev' ]]; then pip install https://www.djangoproject.com/download/1.7c1/tarball/; fi + - [[ $DJANGO != 'dev' ]]; then pip install Django==$DJANGO; fi - pip install https://pypi.python.org/packages/source/p/python-dateutil/python-dateutil-2.1.tar.gz#md5=1534bb15cf311f07afaa3aacba1c028b - python setup.py install script: From 74bd7c3744201db4e2b4e5da28b63fa4f20eb993 Mon Sep 17 00:00:00 2001 From: Clay McClure Date: Thu, 29 May 2014 19:06:51 -0400 Subject: [PATCH 03/13] Include preliminary support for text indexes To index a text field, prefix the field name with `$`, as in `$title`. --- docs/changelog.rst | 1 + docs/guide/defining-documents.rst | 3 ++- mongoengine/base/document.py | 7 +++++-- setup.py | 2 +- tests/document/indexes.py | 14 +++++++++++++- 5 files changed, 22 insertions(+), 5 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 291371fb..9a55b91b 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -6,6 +6,7 @@ Changelog Changes in 0.9.X - DEV ====================== +- Added preliminary support for text indexes #680 - Added `elemMatch` operator as well - `match` is too obscure #653 - Added support for progressive JPEG #486 #548 - Allow strings to be used in index creation #675 diff --git a/docs/guide/defining-documents.rst b/docs/guide/defining-documents.rst index 07bce3bb..85dd0c8b 100644 --- a/docs/guide/defining-documents.rst +++ b/docs/guide/defining-documents.rst @@ -459,7 +459,8 @@ by creating a list of index specifications called :attr:`indexes` in the either be a single field name, a tuple containing multiple field names, or a dictionary containing a full index definition. A direction may be specified on fields by prefixing the field name with a **+** (for ascending) or a **-** sign -(for descending). Note that direction only matters on multi-field indexes. :: +(for descending). Note that direction only matters on multi-field indexes. +Text indexes may be specified by prefixing the field name with a **$**. :: class Page(Document): title = StringField() diff --git a/mongoengine/base/document.py b/mongoengine/base/document.py index 17ff5519..076c04cf 100644 --- a/mongoengine/base/document.py +++ b/mongoengine/base/document.py @@ -680,15 +680,18 @@ class BaseDocument(object): if isinstance(key, (list, tuple)): continue - # ASCENDING from +, + # ASCENDING from + # DESCENDING from - # GEO2D from * + # TEXT from $ direction = pymongo.ASCENDING if key.startswith("-"): direction = pymongo.DESCENDING elif key.startswith("*"): direction = pymongo.GEO2D - if key.startswith(("+", "-", "*")): + elif key.startswith("$"): + direction = pymongo.TEXT + if key.startswith(("+", "-", "*", "$")): key = key[1:] # Use real field name, do it manually because we need field diff --git a/setup.py b/setup.py index 7270331a..f0819fbb 100644 --- a/setup.py +++ b/setup.py @@ -77,7 +77,7 @@ setup(name='mongoengine', long_description=LONG_DESCRIPTION, platforms=['any'], classifiers=CLASSIFIERS, - install_requires=['pymongo>=2.7'], + install_requires=['pymongo>=2.7.1'], test_suite='nose.collector', **extra_opts ) diff --git a/tests/document/indexes.py b/tests/document/indexes.py index 3fc38092..57ee5990 100644 --- a/tests/document/indexes.py +++ b/tests/document/indexes.py @@ -727,7 +727,6 @@ class IndexesTest(unittest.TestCase): report.to_mongo()) self.assertEqual(report, Report.objects.get(pk=my_key)) - def test_string_indexes(self): class MyDoc(Document): @@ -741,6 +740,19 @@ class IndexesTest(unittest.TestCase): self.assertTrue([('provider_ids.foo', 1)] in info) self.assertTrue([('provider_ids.bar', 1)] in info) + def test_text_indexes(self): + + class Book(Document): + title = DictField() + meta = { + "indexes": ["$title"], + } + + indexes = Book.objects._collection.index_information() + self.assertTrue("title_text" in indexes) + key = indexes["title_text"]["key"] + self.assertTrue(('_fts', 'text') in key) + if __name__ == '__main__': unittest.main() From 17d6014bf19f1413130f065e11ef862511fd874c Mon Sep 17 00:00:00 2001 From: Brian Helba Date: Sun, 29 Jun 2014 23:07:28 -0400 Subject: [PATCH 04/13] Fix some minor spelling and grammar in documentation --- docs/guide/connecting.rst | 4 ++-- mongoengine/base/fields.py | 2 +- mongoengine/dereference.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/guide/connecting.rst b/docs/guide/connecting.rst index dd89938b..fcdfe0a3 100644 --- a/docs/guide/connecting.rst +++ b/docs/guide/connecting.rst @@ -35,8 +35,8 @@ in ::func:`~mongoengine.connect` ReplicaSets =========== -MongoEngine supports :class:`~pymongo.mongo_replica_set_client.MongoReplicaSetClient` -to use them please use a URI style connection and provide the `replicaSet` name in the +MongoEngine supports :class:`~pymongo.mongo_replica_set_client.MongoReplicaSetClient`. +To use them, please use a URI style connection and provide the `replicaSet` name in the connection kwargs. Read preferences are supported through the connection or via individual diff --git a/mongoengine/base/fields.py b/mongoengine/base/fields.py index 7329151e..ad173191 100644 --- a/mongoengine/base/fields.py +++ b/mongoengine/base/fields.py @@ -43,7 +43,7 @@ class BaseField(object): :param required: If the field is required. Whether it has to have a value or not. Defaults to False. :param default: (optional) The default value for this field if no value - has been set (or if the value has been unset). It Can be a + has been set (or if the value has been unset). It can be a callable. :param unique: Is the field value unique or not. Defaults to False. :param unique_with: (optional) The other field this field should be diff --git a/mongoengine/dereference.py b/mongoengine/dereference.py index 08eac7dd..18235b96 100644 --- a/mongoengine/dereference.py +++ b/mongoengine/dereference.py @@ -12,7 +12,7 @@ class DeReference(object): def __call__(self, items, max_depth=1, instance=None, name=None): """ Cheaply dereferences the items to a set depth. - Also handles the convertion of complex data types. + Also handles the conversion of complex data types. :param items: The iterable (dict, list, queryset) to be dereferenced. :param max_depth: The maximum depth to recurse to From 646aa131ef93477eae9c29aa33512eb153daf270 Mon Sep 17 00:00:00 2001 From: Yohan Graterol Date: Sun, 29 Jun 2014 22:58:10 -0500 Subject: [PATCH 05/13] Corrected Travis config syntax --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9a076fdc..e735e66f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,8 +28,8 @@ install: - sudo apt-get install python-dev python3-dev libopenjpeg-dev zlib1g-dev libjpeg-turbo8-dev libtiff4-dev libjpeg8-dev libfreetype6-dev liblcms2-dev libwebp-dev tcl8.5-dev tk8.5-dev python-tk - if [[ $PYMONGO == 'dev' ]]; then pip install https://github.com/mongodb/mongo-python-driver/tarball/master; true; fi - if [[ $PYMONGO != 'dev' ]]; then pip install pymongo==$PYMONGO; true; fi - - [[ $DJANGO == 'dev' ]]; then pip install https://www.djangoproject.com/download/1.7c1/tarball/; fi - - [[ $DJANGO != 'dev' ]]; then pip install Django==$DJANGO; fi + - if [[ $DJANGO == 'dev' ]]; then pip install https://www.djangoproject.com/download/1.7c1/tarball/; fi + - if [[ $DJANGO != 'dev' ]]; then pip install Django==$DJANGO; fi - pip install https://pypi.python.org/packages/source/p/python-dateutil/python-dateutil-2.1.tar.gz#md5=1534bb15cf311f07afaa3aacba1c028b - python setup.py install script: From c4ea8d4942a5c96505274dadd91055bcdbf83e23 Mon Sep 17 00:00:00 2001 From: Brian Helba Date: Sun, 29 Jun 2014 23:05:13 -0400 Subject: [PATCH 06/13] Make requirement for PyMongo>=2.5 more consistent Commit 7aa1f473785ed17cff280835285a69e401fd9b86 requires PyMongo >= v2.5. This updates the requirements file to make this requirement explicit to package managers. Commit 29309dac9a926077962fc0778e5b2fbaf1d29cc2 removed some legacy compatibility code that would run only with versions of PyMongo < 2.1. The options 'is_slave' and 'slaves' for register_connection were only used in this compatibility code, so they are removed too. --- mongoengine/connection.py | 16 +++++----------- requirements.txt | 2 +- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/mongoengine/connection.py b/mongoengine/connection.py index fbba3caa..b33ce3a8 100644 --- a/mongoengine/connection.py +++ b/mongoengine/connection.py @@ -19,7 +19,7 @@ _dbs = {} def register_connection(alias, name, host=None, port=None, - is_slave=False, read_preference=False, slaves=None, + read_preference=False, username=None, password=None, authentication_source=None, **kwargs): """Add a connection. @@ -29,12 +29,8 @@ def register_connection(alias, name, host=None, port=None, :param name: the name of the specific database to use :param host: the host name of the :program:`mongod` instance to connect to :param port: the port that the :program:`mongod` instance is running on - :param is_slave: whether the connection can act as a slave - ** Depreciated pymongo 2.0.1+ :param read_preference: The read preference for the collection ** Added pymongo 2.1 - :param slaves: a list of aliases of slave connections; each of these must - be a registered connection that has :attr:`is_slave` set to ``True`` :param username: username to authenticate with :param password: password to authenticate with :param authentication_source: database to authenticate against @@ -47,9 +43,7 @@ def register_connection(alias, name, host=None, port=None, 'name': name, 'host': host or 'localhost', 'port': port or 27017, - 'is_slave': is_slave, 'read_preference': read_preference, - 'slaves': slaves or [], 'username': username, 'password': password, 'authentication_source': authentication_source @@ -67,6 +61,10 @@ def register_connection(alias, name, host=None, port=None, if "replicaSet" in conn_settings['host']: conn_settings['replicaSet'] = True + # Deprecated parameters that should not be passed on + kwargs.pop('slaves', None) + kwargs.pop('is_slave', None) + conn_settings.update(kwargs) _connection_settings[alias] = conn_settings @@ -97,8 +95,6 @@ def get_connection(alias=DEFAULT_CONNECTION_NAME, reconnect=False): conn_settings = _connection_settings[alias].copy() conn_settings.pop('name', None) - conn_settings.pop('slaves', None) - conn_settings.pop('is_slave', None) conn_settings.pop('username', None) conn_settings.pop('password', None) conn_settings.pop('authentication_source', None) @@ -118,8 +114,6 @@ def get_connection(alias=DEFAULT_CONNECTION_NAME, reconnect=False): connection_settings_iterator = ((alias, settings.copy()) for alias, settings in _connection_settings.iteritems()) for alias, connection_settings in connection_settings_iterator: connection_settings.pop('name', None) - connection_settings.pop('slaves', None) - connection_settings.pop('is_slave', None) connection_settings.pop('username', None) connection_settings.pop('password', None) if conn_settings == connection_settings and _connections.get(alias, None): diff --git a/requirements.txt b/requirements.txt index 8c7d698b..ffa42434 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -pymongo \ No newline at end of file +pymongo>=2.4 From fb45b19fdcdb17c476d7591439dc329943312f4f Mon Sep 17 00:00:00 2001 From: Yohan Graterol Date: Sun, 29 Jun 2014 23:26:02 -0500 Subject: [PATCH 07/13] Enabling textSearch for build in Travis --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index e735e66f..81b70433 100644 --- a/.travis.yml +++ b/.travis.yml @@ -32,6 +32,9 @@ install: - if [[ $DJANGO != 'dev' ]]; then pip install Django==$DJANGO; fi - pip install https://pypi.python.org/packages/source/p/python-dateutil/python-dateutil-2.1.tar.gz#md5=1534bb15cf311f07afaa3aacba1c028b - python setup.py install +before_script: + - sleep 15 + - mongo --eval 'db.adminCommand( { setParameter : 1, textSearchEnabled : true } )' script: - python setup.py test - if [[ $TRAVIS_PYTHON_VERSION == '3.'* ]]; then 2to3 . -w; fi; From c71fd1ee3b17c063ee9d04d56b53d3b5593e0757 Mon Sep 17 00:00:00 2001 From: Yohan Graterol Date: Sun, 29 Jun 2014 23:29:10 -0500 Subject: [PATCH 08/13] Before_script fixed. --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 81b70433..46b914a3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -32,9 +32,10 @@ install: - if [[ $DJANGO != 'dev' ]]; then pip install Django==$DJANGO; fi - pip install https://pypi.python.org/packages/source/p/python-dateutil/python-dateutil-2.1.tar.gz#md5=1534bb15cf311f07afaa3aacba1c028b - python setup.py install + before_script: - - sleep 15 - mongo --eval 'db.adminCommand( { setParameter : 1, textSearchEnabled : true } )' + script: - python setup.py test - if [[ $TRAVIS_PYTHON_VERSION == '3.'* ]]; then 2to3 . -w; fi; From f2992e3165d394b803f1ac7480f8be31b28dcc99 Mon Sep 17 00:00:00 2001 From: Yohan Graterol Date: Sun, 29 Jun 2014 23:31:08 -0500 Subject: [PATCH 09/13] Travis problem with before_script --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 46b914a3..879ca91b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,8 +33,7 @@ install: - pip install https://pypi.python.org/packages/source/p/python-dateutil/python-dateutil-2.1.tar.gz#md5=1534bb15cf311f07afaa3aacba1c028b - python setup.py install -before_script: - - mongo --eval 'db.adminCommand( { setParameter : 1, textSearchEnabled : true } )' +before_script: mongo --eval 'db.adminCommand( { setParameter : 1, textSearchEnabled : true } )' script: - python setup.py test From e88f8759e70e74bbe04a3bd1815bacda756546dd Mon Sep 17 00:00:00 2001 From: Yohan Graterol Date: Sun, 29 Jun 2014 23:33:30 -0500 Subject: [PATCH 10/13] Replace before_script for before_install --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 879ca91b..3250b3d2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,8 @@ # http://travis-ci.org/#!/MongoEngine/mongoengine language: python services: mongodb +before_install: + - "mongo --eval 'db.runCommand({setParameter: 1, textSearchEnabled: true})' admin" python: - "2.6" - "2.7" @@ -33,8 +35,6 @@ install: - pip install https://pypi.python.org/packages/source/p/python-dateutil/python-dateutil-2.1.tar.gz#md5=1534bb15cf311f07afaa3aacba1c028b - python setup.py install -before_script: mongo --eval 'db.adminCommand( { setParameter : 1, textSearchEnabled : true } )' - script: - python setup.py test - if [[ $TRAVIS_PYTHON_VERSION == '3.'* ]]; then 2to3 . -w; fi; From 27c33911e6183d43518dcad23e368a38fcb08a98 Mon Sep 17 00:00:00 2001 From: Yohan Graterol Date: Mon, 30 Jun 2014 00:09:28 -0500 Subject: [PATCH 11/13] Update .travis.yml --- .travis.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3250b3d2..5c8b2492 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,6 @@ # http://travis-ci.org/#!/MongoEngine/mongoengine language: python services: mongodb -before_install: - - "mongo --eval 'db.runCommand({setParameter: 1, textSearchEnabled: true})' admin" python: - "2.6" - "2.7" @@ -34,7 +32,7 @@ install: - if [[ $DJANGO != 'dev' ]]; then pip install Django==$DJANGO; fi - pip install https://pypi.python.org/packages/source/p/python-dateutil/python-dateutil-2.1.tar.gz#md5=1534bb15cf311f07afaa3aacba1c028b - python setup.py install - +before_script: "mongo --eval 'db.runCommand({setParameter: 1, textSearchEnabled: true})' admin" script: - python setup.py test - if [[ $TRAVIS_PYTHON_VERSION == '3.'* ]]; then 2to3 . -w; fi; From 938cdf316aeb17c902cc5ba1610979451b2ec00c Mon Sep 17 00:00:00 2001 From: Yohan Graterol Date: Mon, 30 Jun 2014 00:14:47 -0500 Subject: [PATCH 12/13] Added cache for apt in Travis --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 5c8b2492..81bf54b8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,6 @@ # http://travis-ci.org/#!/MongoEngine/mongoengine language: python +cache: apt services: mongodb python: - "2.6" From c10e808a4f45e42d080328ce317b33da4306ddaf Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Mon, 30 Jun 2014 11:30:51 +0300 Subject: [PATCH 13/13] Fixed requirements file to fit the new PyMongo>=2.7.1 requirement. --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index ffa42434..f2164a2c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -pymongo>=2.4 +pymongo>=2.7.1