List<MappingField> resolveFields(
            @Nonnull String[] externalName,
            @Nullable String dataConnectionName,
            @Nonnull Map<String, String> options,
            @Nonnull List<MappingField> userFields,
            boolean stream
    ) {
        Predicate<MappingField> pkColumnName = Options.getPkColumnChecker(options, stream);
        Map<String, DocumentField> dbFields = readFields(externalName, dataConnectionName, options, stream);

        List<MappingField> resolvedFields = new ArrayList<>();
        if (userFields.isEmpty()) {
            for (DocumentField documentField : dbFields.values()) {
                MappingField mappingField = new MappingField(
                        documentField.columnName,
                        resolveType(documentField.columnType),
                        documentField.columnName,
                        documentField.columnType.name()
                );
                mappingField.setPrimaryKey(pkColumnName.test(mappingField));
                resolvedFields.add(mappingField);
            }
        } else {
            for (MappingField f : userFields) {
                String prefixIfStream = stream ? "fullDocument." : "";
                String nameInMongo = f.externalName() == null ? prefixIfStream + f.name() : f.externalName();

                DocumentField documentField = getField(dbFields, f, stream);
                if (documentField == null) {
                    throw new IllegalArgumentException("Could not resolve field with name " + nameInMongo);
                }
                MappingField mappingField = new MappingField(f.name(), f.type(), documentField.columnName,
                        documentField.columnType.name());
                mappingField.setPrimaryKey(pkColumnName.test(mappingField));
                validateType(f, documentField);
                resolvedFields.add(mappingField);
            }
        }
        return resolvedFields;
    }
@Test
    public void testFailsOnNoDatabase() {
        String collectionName = "people_3";
        FieldResolver resolver = new FieldResolver(null);

        Map<String, String> readOpts = new HashMap<>();
        readOpts.put("connectionString", mongoContainer.getConnectionString());
        try {
            resolver.resolveFields(new String[]{collectionName}, null, readOpts, singletonList(
                    new MappingField("id", QueryDataType.MAP).setExternalName("_id")
            ), false);
        } catch (IllegalArgumentException e) {
            assertThat(e.getMessage()).isEqualTo("Database must be provided in the mapping or data connection.");
        }
    }