diff --git a/mongoengine/document.py b/mongoengine/document.py index e26c5ed0..d7154404 100644 --- a/mongoengine/document.py +++ b/mongoengine/document.py @@ -67,8 +67,6 @@ class Document(BaseDocument): def reload(self): """Reloads all attributes from the database. """ - #object_id = self._fields['id'].to_mongo(self.id) - #obj = self.__class__.objects(id=object_id).first() obj = self.__class__.objects(id=self.id).first() for field in self._fields: setattr(self, field, getattr(obj, field)) diff --git a/mongoengine/queryset.py b/mongoengine/queryset.py index 75a92751..96c23594 100644 --- a/mongoengine/queryset.py +++ b/mongoengine/queryset.py @@ -25,7 +25,7 @@ class QuerySet(object): self._query = {'_types': self._document._class_name} self._cursor_obj = None - def ensure_index(self, key_or_list, direction=None): + def ensure_index(self, key_or_list): """Ensure that the given indexes are in place. """ if isinstance(key_or_list, basestring): diff --git a/tests/document.py b/tests/document.py index 47d9c5c4..a6abca89 100644 --- a/tests/document.py +++ b/tests/document.py @@ -221,6 +221,32 @@ class DocumentTest(unittest.TestCase): Log.drop_collection() + def test_indexes(self): + """Ensure that indexes are used when meta[indexes] is specified. + """ + class BlogPost(Document): + date = DateTimeField(default=datetime.datetime.now) + category = StringField() + meta = { + 'indexes': [ + '-date', + ('category', '-date') + ], + } + + BlogPost.drop_collection() + + info = BlogPost.objects._collection.index_information() + self.assertEqual(len(info), 0) + + BlogPost.objects() + info = BlogPost.objects._collection.index_information() + self.assertTrue([('category', 1), ('date', -1)] in info.values()) + # Even though descending order was specified, single-key indexes use 1 + self.assertTrue([('date', 1)] in info.values()) + + BlogPost.drop_collection() + def test_creation(self): """Ensure that document may be created using keyword arguments. """