def METHOD_NAME(
        document_ids, base_query, documents_config, lang):
    """ Load the documents for the ids and return them as json dict.
    The returned list contains None values for documents that could not be
    loaded, and the list has the same order has the document id list.
    """
    base_query = base_query.options(
        load_only(*documents_config.get_load_only_fields())
    )
    base_query = add_load_for_locales(
        base_query, documents_config.clazz, documents_config.clazz_locale,
        documents_config.get_load_only_fields_locales())
    if len(documents_config.get_load_only_fields_geometry()) > 1:
        # only load the geometry if the fields list contains other columns than
        # 'version'
        base_query = base_query.options(
            joinedload(getattr(documents_config.clazz, 'geometry')).
            load_only(*documents_config.get_load_only_fields_geometry())
        )
    if documents_config.include_areas:
        base_query = base_query. \
            options(
                joinedload(getattr(documents_config.clazz, '_areas')).
                load_only(
                    'document_id', 'area_type', 'version', 'protected',
                    'type').
                joinedload('locales').
                load_only(
                    'lang', 'title', 'version')
            )
    documents = _load_documents(
        document_ids, documents_config.clazz, base_query)
    set_available_langs(documents, loaded=True)
    if lang is not None:
        set_best_locale(documents, lang)
    if documents_config.include_areas:
        _set_areas_for_documents(documents, lang)
    if documents_config.include_img_count:
        _set_img_count_for_documents(documents, document_ids)
    if documents_config.set_custom_fields:
        documents_config.set_custom_fields(documents, lang)
    # make sure the documents are returned in the same order
    document_index = {doc.document_id: doc for doc in documents}
    documents = [document_index.get(id) for id in document_ids]
    return [
        to_json_dict(
            doc,
            documents_config.schema if not documents_config.adapt_schema
            else documents_config.adapt_schema(
                documents_config.schema, doc),
            with_special_geometry_attrs=True
        ) if doc else None for doc in documents
        ]