问题
使用 Ubuntu 20.04 apt 安装的 mongodump,备份云上的 MongoDB 服务数据时,报错 Failed: error writing data for collection `xxx_prod_marketdata.marketdata04_xxx.sec` to disk: error reading collection: Failed to parse: { find: "marketdata04_xxx.sec", skip: 0, snapshot: true, $readPreference: { mode: "secondaryPreferred" }, $db: "xxx_prod_marketdata" }. Unrecognized field 'snapshot'.
分析
系统自带的 mongo-tools 版本太低
# mongodump --version
mongodump version: built-without-version-string
git version: built-without-git-spec
Go version: go1.10.1
os: linux
arch: amd64
compiler: gc
OpenSSL version: OpenSSL 1.1.0g 2 Nov 2017
解决办法
卸载掉老版本的 mongo-tools ,安装新版本的 mongodb-database-tools,工具下载页面 https://www.mongodb.com/try/download/database-tools
# apt remove mongo-tools -y
# wget https://fastdl.mongodb.org/tools/db/mongodb-database-tools-ubuntu2004-x86_64-100.12.0.deb
# apt install -y ./mongodb-database-tools-ubuntu2004-x86_64-100.12.0.deb
# mongodump --version
mongodump version: 100.12.0
git version: 4558399ef8d5aa59a2779d5909fe9713da43b6af
Go version: go1.23.7
os: linux
arch: amd64
compiler: gc