parent
be8d39a48c
commit
1b80193aac
@ -4,7 +4,8 @@ Changelog
|
||||
|
||||
Changes in 0.7.X
|
||||
=================
|
||||
- Fixed ImageField resizing when forcing size
|
||||
- Added example of indexing embedded document fields (MongoEngine/mongoengine#75)
|
||||
- Fixed ImageField resizing when forcing size (MongoEngine/mongoengine#80)
|
||||
- Add flexibility for fields handling bad data (MongoEngine/mongoengine#78)
|
||||
- Embedded Documents no longer handle meta definitions
|
||||
- Use weakref proxies in base lists / dicts (MongoEngine/mongoengine#74)
|
||||
|
@ -467,11 +467,16 @@ If a dictionary is passed then the following options are available:
|
||||
:attr:`unique` (Default: False)
|
||||
Whether the index should be sparse.
|
||||
|
||||
.. note ::
|
||||
|
||||
To index embedded files / dictionary fields use 'dot' notation eg:
|
||||
`rank.title`
|
||||
|
||||
.. warning::
|
||||
|
||||
|
||||
Inheritance adds extra indices.
|
||||
If don't need inheritance for a document turn inheritance off - see :ref:`document-inheritance`.
|
||||
Inheritance adds extra indices.
|
||||
If don't need inheritance for a document turn inheritance off -
|
||||
see :ref:`document-inheritance`.
|
||||
|
||||
|
||||
Geospatial indexes
|
||||
|
@ -740,6 +740,30 @@ class DocumentTest(unittest.TestCase):
|
||||
self.assertEqual(Person.objects.get(name="Jack").rank, "Corporal")
|
||||
self.assertEqual(Person.objects.get(name="Fred").rank, "Private")
|
||||
|
||||
def test_embedded_document_index_meta(self):
|
||||
"""Ensure that embedded document indexes are created explicitly
|
||||
"""
|
||||
class Rank(EmbeddedDocument):
|
||||
title = StringField(required=True)
|
||||
|
||||
class Person(Document):
|
||||
name = StringField(required=True)
|
||||
rank = EmbeddedDocumentField(Rank, required=False)
|
||||
|
||||
meta = {
|
||||
'indexes': [
|
||||
'rank.title',
|
||||
],
|
||||
}
|
||||
|
||||
Person.drop_collection()
|
||||
|
||||
# Indexes are lazy so use list() to perform query
|
||||
list(Person.objects)
|
||||
info = Person.objects._collection.index_information()
|
||||
info = [value['key'] for key, value in info.iteritems()]
|
||||
self.assertTrue([('rank.title', '1')] in info)
|
||||
|
||||
def test_explicit_geo2d_index(self):
|
||||
"""Ensure that geo2d indexes work when created via meta[indexes]
|
||||
"""
|
||||
@ -770,7 +794,7 @@ class DocumentTest(unittest.TestCase):
|
||||
tags = ListField(StringField())
|
||||
meta = {
|
||||
'indexes': [
|
||||
{ 'fields': ['-date'], 'unique': True,
|
||||
{'fields': ['-date'], 'unique': True,
|
||||
'sparse': True, 'types': False },
|
||||
],
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user