diff --git a/lib/dbi/ogs-mongoc.c b/lib/dbi/ogs-mongoc.c
index 8082bb0db..05f5ff128 100644
--- a/lib/dbi/ogs-mongoc.c
+++ b/lib/dbi/ogs-mongoc.c
@@ -17,12 +17,14 @@
* along with this program. If not, see .
*/
-#include
-
#include "ogs-dbi.h"
int __ogs_dbi_domain;
+#ifdef OGS_DBI_WITH_MONGODB
+#include
+
+
static ogs_mongoc_t self;
/*
diff --git a/lib/dbi/ogs-mongoc.h b/lib/dbi/ogs-mongoc.h
index 9e3b4515b..f7f2f3764 100644
--- a/lib/dbi/ogs-mongoc.h
+++ b/lib/dbi/ogs-mongoc.h
@@ -24,12 +24,11 @@
#ifndef OGS_MONGOC_H
#define OGS_MONGOC_H
-#include
-
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
+
typedef struct ogs_mongoc_s {
bool initialized;
const char *name;
diff --git a/meson.build b/meson.build
index 021f40e6d..19bed8754 100644
--- a/meson.build
+++ b/meson.build
@@ -115,7 +115,7 @@ subdir('src')
subdir('misc')
# Don't build the tests unless we can run them (either natively or in an exe wrapper)
build_tests = not meson.is_cross_build() or (meson.is_cross_build() and meson.has_exe_wrapper())
-if build_tests
+if build_tests and get_option('mongodb')
subdir('tests')
endif