def create_collection_index(collection, keys, ignore_created=True, ignore_created_opts=True, **kwargs):
 INDEX_ALREADY_EXISTS = 68
 INDEX_OPTIONS_CONFLICT = 85
 try:
  collection.create_index(keys, **kwargs)
 except pymongo.errors.OperationFailure as exc:
  errors_to_ignore = []
  if ignore_created:
   errors_to_ignore.append(INDEX_ALREADY_EXISTS)
  if ignore_created_opts:
   errors_to_ignore.append(INDEX_OPTIONS_CONFLICT)
  if (exc.code in errors_to_ignore):
   logger.warning("Existing index in collection '{}' remained unchanged!: {}".format(collection.full_name, exc.details['errmsg']))
  else:
   raise exc

def create_collection_index ( collection , keys , ignore_created = True , ignore_created_opts = True , ** kwargs ) : INDEX_ALREADY_EXISTS = 68 INDEX_OPTIONS_CONFLICT = 85 try : collection . create_index ( keys , ** kwargs ) except pymongo . errors . OperationFailure as exc : errors_to_ignore = [ ] if ignore_created : errors_to_ignore . append ( INDEX_ALREADY_EXISTS ) if ignore_created_opts : errors_to_ignore . append ( INDEX_OPTIONS_CONFLICT ) if ( exc . code in errors_to_ignore ) : logger . warning ( "Existing index in collection '{}' remained unchanged!: {}" . format ( collection . full_name , exc . details [ 'errmsg' ] ) ) else : raise exc
create a mongodb index in a collection .