docs: def index(db, collection, fields, directions=None, desc=False, background=False):
      '''
      Builds a simple (single field) or complex (multiple fields) index
      on a single collection in a MongoDB database.
  
      Args:
  
          db (Database): A pymongo Database object.
  
          collection (str): Collection name.
  
          fields: Can be one of two things:
  
              - the name of a single field, as a string
              - an iterable (list/tuple) of one or more field names
  
          desc (bool): If ``True``, all indexes will be created in descending order.
              Default is ``False``.
  
          directions (list): For complex indexes for which you'd like to have
              different indexing directions (ascending for some fields, descending
              for others), you can pass a list of pymongo direction objects (
              pymongo.ASCENDING and pymongo.DESCENDING), in the same order as the
              list of fields to be indexed. Must be the same length as the list
              of index fields. Default is ``None``.
  
          background (bool): If ``True``, the indexing operation will be processed
              in the background. When performing background indexes, the MongoDB
              database will not be locked.
      '''
      import pymongo
      if type(fields) in STR_TYPES:
          fields = [fields, ]
      if directions is None:
          _dir = pymongo.DESCENDING if desc else pymongo.ASCENDING
          directions = [_dir] * len(fields)
      field_tuples = list(zip(fields, directions))
      coll = db[collection]
      coll.create_index(field_tuples, background=background)