diff --git a/meta-oe/dynamic-layers/meta-python/recipes-dbs/mongodb/mongodb/oe-buildinfo.vars b/meta-oe/dynamic-layers/meta-python/recipes-dbs/mongodb/mongodb/oe-buildinfo.vars
new file mode 100644
index 0000000000..950dc4baa2
--- /dev/null
+++ b/meta-oe/dynamic-layers/meta-python/recipes-dbs/mongodb/mongodb/oe-buildinfo.vars
@@ -0,0 +1,11 @@
+# Keep the compiler and its flags, which carry build paths, out of
+# the buildInfo command and --version output
+from mongo.generators import default_buildinfo_environment_data
+
+MONGO_BUILDINFO_ENVIRONMENT_DATA = {
+    k: v for k, v in default_buildinfo_environment_data().items()
+    if k not in ('cc', 'ccflags', 'cxx', 'cxxflags', 'linkflags')
+}
+
+# SConstruct rejects unknown names left in a variables file
+del default_buildinfo_environment_data
diff --git a/meta-oe/dynamic-layers/meta-python/recipes-dbs/mongodb/mongodb_git.bb b/meta-oe/dynamic-layers/meta-python/recipes-dbs/mongodb/mongodb_git.bb
index 22169ddd64..6c4fdf91a9 100644
--- a/meta-oe/dynamic-layers/meta-python/recipes-dbs/mongodb/mongodb_git.bb
+++ b/meta-oe/dynamic-layers/meta-python/recipes-dbs/mongodb/mongodb_git.bb
@@ -41,6 +41,7 @@ SRC_URI = "git://github.com/mongodb/mongo.git;branch=v4.4;protocol=https \
            file://0003-boost-Fix-build-with-clang-23.patch \
            file://0004-ssl-Fix-build-with-OpenSSL-4.patch \
            file://0005-SERVER-49099-Remove-the-Node-swap-function-in-Biggie.patch \
+           file://oe-buildinfo.vars \
            "
 SRC_URI:append:libc-musl = "\
            file://0001-Mark-one-of-strerror_r-implementation-glibc-specific.patch \
@@ -87,6 +88,7 @@ EXTRA_OESCONS = "PREFIX=${prefix} \
                  TARGET_ARCH=${MONGO_ARCH} \
                  MONGO_VERSION=${PV} \
                  OBJCOPY=${OBJCOPY} \
+                 --variables-files=${UNPACKDIR}/oe-buildinfo.vars \
                  --ssl \
                  --disable-warnings-as-errors \
                  --use-system-zlib \
