You can create indexes for each collection using Index class. Its fairy easy but you should be familiar with indexing in databases. bad index could lead to poor performance.
This class represent a Mongodb collection Index. You must using it via :py:attribute: ~djamo.collection.BaseCollection.indexes for example:
class Students(Collection):
indexes = [
Index("name", unique=True),
Index(["age", "uid"]),
]
Note
You can use Index separatly by using its ensure method.
All optional index creation paramaters should be passed as keyword arguments to this method. Valid options include:
a name will be generated
unique: should this index guarantee uniqueness?
dropDups or drop_dups: should we drop duplicates
background: if this index should be created in the background
Number of documents to group together within a certain proximity to a given longitude and latitude.
min: minimum value for keys in a GEO2D index
max: maximum value for keys in a GEO2D index
MongoDB will automatically delete documents from this collection after <int> seconds. The indexed field must be a UTC datetime or the data will not expire.
Parameters: |
|
---|
Create the index if it does not exists.
Parameters: | collection – Collection object to create the index for. |
---|