Return a mongodb connection object

def _get_conn(ret):
    '''
    Return a mongodb connection object
    '''
    _options = _get_options(ret)

    host = _options.get('host')
    port = _options.get('port')
    uri = _options.get('uri')
    db_ = _options.get('db')
    user = _options.get('user')
    password = _options.get('password')
    indexes = _options.get('indexes', False)

    # at some point we should remove support for
    # pymongo versions < 2.3 until then there are
    # a bunch of these sections that need to be supported
    if uri and PYMONGO_VERSION > _LooseVersion('2.3'):
        if uri and host:
            raise salt.exceptions.SaltConfigurationError(
                    "Mongo returner expects either uri or host configuration. Both were provided")
        pymongo.uri_parser.parse_uri(uri)
        conn = pymongo.MongoClient(uri)
        mdb = conn.get_database()
    else:
        if PYMONGO_VERSION > _LooseVersion('2.3'):
            conn = pymongo.MongoClient(host, port)
        else:
            if uri:
                raise salt.exceptions.SaltConfigurationError(
                    "pymongo <= 2.3 does not support uri format")
            conn = pymongo.Connection(host, port)

        mdb = conn[db_]
        if user and password:
            mdb.authenticate(user, password)

    if indexes:
        if PYMONGO_VERSION > _LooseVersion('2.3'):
            mdb.saltReturns.create_index('minion')
            mdb.saltReturns.create_index('jid')
            mdb.jobs.create_index('jid')
            mdb.events.create_index('tag')
        else:
            mdb.saltReturns.ensure_index('minion')
            mdb.saltReturns.ensure_index('jid')
            mdb.jobs.ensure_index('jid')
            mdb.events.ensure_index('tag')

    return conn, mdb