You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

为何Docker单实例MongoDB不支持多文档事务而Windows安装版支持?

MongoDB单实例事务支持差异分析

测试MongoDB多文档事务时发现:使用Docker部署的mongodb/mongodb-community-server:latest单实例会报错,提示单实例不支持事务(官方文档也有相关说明);但通过Windows安装程序部署的MongoDB社区版单实例却可以正常使用事务。现针对二者的差异进行分析(已知Docker可通过配置副本集实现事务,此方案不在讨论范围内)。


Docker容器部署信息

集群描述

{ ClusterId : "1", Type : "Unknown", State : "Disconnected", Servers : [{ ServerId: "{ ClusterId : 1, EndPoint : "Unspecified/localhost:27017" }", EndPoint: "Unspecified/localhost:27017", ReasonChanged: "ServerInitialDescription", State: "Disconnected", ServerVersion: , TopologyVersion: , Type: "Unknown", LastHeartbeatTimestamp: null, LastUpdateTimestamp: "2024-01-26T00:58:47.1630530Z" }] }

Build Info

{ "version" : "7.0.4", "gitVersion" : "38f3e37057a43d2e9f41a39142681a76062d582e", "modules" : [], "allocator" : "tcmalloc", "javascriptEngine" : "mozjs", "sysInfo" : "deprecated", "versionArray" : [7, 0, 4, 0], "openssl" : { "running" : "OpenSSL 3.0.2 15 Mar 2022", "compiled" : "OpenSSL 3.0.2 15 Mar 2022" }, "buildEnvironment" : { "distmod" : "ubuntu2204", "distarch" : "aarch64", "cc" : "/opt/mongodbtoolchain/v4/bin/gcc: gcc (GCC) 11.3.0", "ccflags" : "-Werror -include mongo/platform/basic.h -ffp-contract=off -fasynchronous-unwind-tables -g2 -Wall -Wsign-compare -Wno-unknown-pragmas -Winvalid-pch -gdwarf-5 -fno-omit-frame-pointer -fno-strict-aliasing -O2 -march=armv8.2-a -mtune=generic -Wno-unused-local-typedefs -Wno-unused-function -Wno-deprecated-declarations -Wno-unused-const-variable -Wno-unused-but-set-variable -Wno-missing-braces -fstack-protector-strong -gdwarf64 -Wa,--nocompress-debug-sections -Wimplicit-fallthrough=5", "cxx" : "/opt/mongodbtoolchain/v4/bin/g++: g++ (GCC) 11.3.0", "cxxflags" : "-Woverloaded-virtual -Wpessimizing-move -Wno-maybe-uninitialized -fsized-deallocation -Wno-deprecated -std=c++20", "linkflags" : "-Wl,--fatal-warnings -B/opt/mongodbtoolchain/v4/bin -gdwarf-5 -pthread -Wl,-z,now -fuse-ld=lld -fstack-protector-strong -gdwarf64 -Wl,--build-id -Wl,--hash-style=gnu -Wl,-z,noexecstack -Wl,--warn-execstack -Wl,-z,relro -Wl,--compress-debug-sections=none -Wl,-z,origin -Wl,--enable-new-dtags", "target_arch" : "aarch64", "target_os" : "linux", "cppdefines" : "SAFEINT_USE_INTRINSICS 0 PCRE2_STATIC NDEBUG _XOPEN_SOURCE 700 _GNU_SOURCE _FORTIFY_SOURCE 2 ABSL_FORCE_ALIGNED_ACCESS BOOST_ENABLE_ASSERT_DEBUG_HANDLER BOOST_FILESYSTEM_NO_CXX20_ATOMIC_REF BOOST_LOG_NO_SHORTHAND_NAMES BOOST_LOG_USE_NATIVE_SYSLOG BOOST_LOG_WITHOUT_THREAD_ATTR BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS BOOST_SYSTEM_NO_DEPRECATED BOOST_THREAD_USES_DATETIME BOOST_THREAD_VERSION 5" }, "bits" : 64, "debug" : false, "maxBsonObjectSize" : 16777216, "storageEngines" : ["devnull", "wiredTiger"], "ok" : 1.0 }

Windows安装部署信息

集群描述

{ ClusterId : "1", Type : "Unknown", State : "Disconnected", Servers : [{ ServerId: "{ ClusterId : 1, EndPoint : "10.69.13.10:27017" }", EndPoint: "10.69.13.10:27017", ReasonChanged: "ServerInitialDescription", State: "Disconnected", ServerVersion: , TopologyVersion: , Type: "Unknown", LastHeartbeatTimestamp: null, LastUpdateTimestamp: "2024-01-25T06:24:31.0074383Z" }] }

Build Info

{ "version" : "6.0.1", "gitVersion" : "32f0f9c88dc44a2c8073a5bd47cf779d4bfdee6b", "targetMinOS" : "Windows 7/Windows Server 2008 R2", "modules" : [], "allocator" : "tcmalloc", "javascriptEngine" : "mozjs", "sysInfo" : "deprecated", "versionArray" : [6, 0, 1, 0], "openssl" : { "running" : "Windows SChannel" }, "buildEnvironment" : { "distmod" : "windows", "distarch" : "x86_64", "cc" : "cl: Microsoft (R) C/C++ Optimizing Compiler Version 19.31.31107 for x64", "ccflags" : "/nologo /WX /FImongo/platform/basic.h /EHsc /W3 /wd4068 /wd4244 /wd4267 /wd4290 /wd4351 /wd4355 /wd4373 /wd4800 /wd4251 /wd4291 /we4013 /we4099 /we4930 /errorReport:none /MD /O2 /Oy- /bigobj /utf-8 /permissive- /Zc:__cplusplus /Zc:sizedDealloc /volatile:iso /diagnostics:caret /std:c++17 /Gw /Gy /Zc:inline", "cxx" : "cl: Microsoft (R) C/C++ Optimizing Compiler Version 19.31.31107 for x64", "cxxflags" : "/TP", "linkflags" : "/nologo /DEBUG /INCREMENTAL:NO /LARGEADDRESSAWARE /OPT:REF", "target_arch" : "x86_64", "target_os" : "windows", "cppdefines" : "SAFEINT_USE_INTRINSICS 0 PCRE_STATIC NDEBUG BOOST_ALL_NO_LIB _UNICODE UNICODE _SILENCE_CXX17_ALLOCATOR_VOID_DEPRECATION_WARNING _SILENCE_CXX17_OLD_ALLOCATOR_MEMBERS_DEPRECATION_WARNING _SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING _SILENCE_ALL_CXX20_DEPRECATION_WARNINGS _CONSOLE _CRT_SECURE_NO_WARNINGS _ENABLE_EXTENDED_ALIGNED_STORAGE _SCL_SECURE_NO_WARNINGS _WIN32_WINNT 0x0A00 BOOST_USE_WINAPI_VERSION 0x0A00 NTDDI_VERSION 0x0A000000 BOOST_THREAD_VERSION 5 BOOST_THREAD_USES_DATETIME BOOST_SYSTEM_NO_DEPRECATED BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS BOOST_ENABLE_ASSERT_DEBUG_HANDLER BOOST_LOG_NO_SHORTHAND_NAMES BOOST_LOG_USE_NATIVE_SYSLOG BOOST_LOG_WITHOUT_THREAD_ATTR ABSL_FORCE_ALIGNED_ACCESS" }, "bits" : 64, "debug" : false, "maxBsonObjectSize" : 16777216, "storageEngines" : ["devnull", "ephemeralForTest", "wiredTiger"], "ok" : 1.0 }

核心差异分析

1. 版本迭代带来的规则变化

Docker部署的是MongoDB社区版7.0.4,Windows部署的是6.0.1:

  • MongoDB 7.0版本起,官方严格执行事务环境校验,明确单实例(非副本集/分片集群)不支持多文档事务,直接拦截相关操作并抛出错误
  • 6.x版本中,虽然官方文档标注事务需要副本集环境,但实际未完全限制单实例的事务使用,属于兼容保留的行为,只要使用WiredTiger存储引擎即可执行多文档事务

2. 构建配置的严格性差异

  • Docker镜像的7.0.4版本基于Ubuntu 22.04编译,构建参数中启用了严格的环境校验逻辑,强制要求事务必须在分布式集群环境下运行
  • Windows 6.0.1版本的编译配置未加入该严格校验,保留了单实例下的事务执行权限

内容的提问来源于stack exchange,提问作者Md. Rasedur Rahman Roxy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 17:44:59