code: def _format_mongodb_uri(parsed_uri):
      
      user_pass = ''
      if parsed_uri.get('username') and parsed_uri.get('password'):
          user_pass = '{username!s}:{password!s}@'.format(**parsed_uri)
  
      _nodes = []
      for host, port in parsed_uri.get('nodelist'):
          if ':' in host and not host.endswith(']'):
              # IPv6 address without brackets
              host = '[{!s}]'.format(host)
          if port == 27017:
              _nodes.append(host)
          else:
              _nodes.append('{!s}:{!s}'.format(host, port))
      nodelist = ','.join(_nodes)
  
      options = ''
      if parsed_uri.get('options'):
          _opt_list = []
          for key, value in parsed_uri.get('options').items():
              if isinstance(value, bool):
                  value = str(value).lower()
              _opt_list.append('{!s}={!s}'.format(key, value))
          options = '?' + '&'.join(_opt_list)
  
      db_name = parsed_uri.get('database') or ''
  
      res = "mongodb://{user_pass!s}{nodelist!s}/{db_name!s}{options!s}".format(
          user_pass=user_pass,
          nodelist=nodelist,
          db_name=db_name,
          # collection is ignored
          options=options)
      return res
docs: Painstakingly reconstruct a MongoDB URI parsed using pymongo.uri_parser.parse_uri.
  
      :param parsed_uri: Result of pymongo.uri_parser.parse_uri
      :type parsed_uri: dict
  
      :return: New URI
      :rtype: str | unicode