def _create_unique_index(self):
"""Create an index based on raw data reference fields.
Creates a compound index on the fields that contain the location
of the raw data from which a document was derived. This prevents
duplicate documents from being saved.
"""
data_key = _DISTILLERY_SETTINGS['RAW_DATA_KEY']
fields = [
'BACKEND_KEY',
'WAREHOUSE_KEY',
'COLLECTION_KEY',
'DOC_ID_KEY'
]
keys = ['%s.%s' % (data_key, _DISTILLERY_SETTINGS[field])
for field in fields]
formatted_keys = [(key, pymongo.ASCENDING) for key in keys]
return self._collection.create_index(formatted_keys, unique=True,
sparse=True)
评论列表
文章目录