mongocxx mongosh db.currentOp BSONError: BSON 文档中的无效 UTF-8 字符串

huangapple go评论120阅读模式
英文:

mongocxx mongosh db.currentOp BSONError: Invalid UTF-8 string in BSON document

问题

I use debian9 and debian10 mongocxx driver to insert data in mongodb 6.0. Then I use mongosh 1.6 for monitoring ops with db.currentOp. And I get an error BSONError: Invalid UTF-8 string in BSON document.

I can switch on profiling and look for ops profiles with db.system.profile.find. I see, that profile, except user data, contains driver description data, like this:

'$client': {
driver: { name: 'Н\x07\x18_\x7F', version: 'kafkaclient' },
...
platform: 'networks/lib/x86_64-linux-gnu`G\b\x18_\x7F', Such driver name DONT lead to error with BSON. But sometime I see driver description data, like this:

'$client': {
driver: { name: 'Н\x07��\x7F', version: 'kafkaclient' },
...
platform: 'networks/lib/x86_64-linux-gnu`G\b��\x7F'

�� - this simbols cause the BSON error for db.system.profile.find and db.currentOp. For db.system.profile.find I can use enableUtf8Validation = false and avoid the error. But for currentOp I can't use enableUtf8Validation. But I should to use db.currentOp for ops monitoring. I have next questions:

  1. 对于相同的操作系统、mongocxx 驱动程序、mongodb 和 mongosh,驱动程序名称数据可以在 C++ 客户端和 mongodb 之间的会话之间不同。为什么?
  2. 我是否可以禁用 db.currentOp 的 UTF8 验证?
  3. 为什么 mongocxx + mongodb + debian 可能会出现 BSON UTF8 错误?可能的原因是什么:mongocxx 驱动程序、debian 操作系统、mongodb?

(Note: The text in question 1 contains some symbols that are not clearly represented, making it difficult to provide an accurate translation. The text mentions differences in driver name data between sessions.)

英文:

I use debian9 and debian10 mongocxx driver to insert data in mongodb 6.0. Then I use mongosh 1.6 for monitoring ops with db.currentOp. And I get an error
BSONError: Invalid UTF-8 string in BSON document.

I can switch on profiling and look for ops profiles with db.system.profile.find. I see, that profile, except user data, contains driver description data, like this:

'$client': {
driver: { name: 'Н\x07\x18_\x7F', version: 'kafkaclient' },
...
platform: 'networks/lib/x86_64-linux-gnu`G\b\x18_\x7F',

Such driver name DONT lead to error with BSON. But sometime I see driver description data, like this:

'$client': {
driver: { name: 'Н\x07��\x7F', version: 'kafkaclient' },
...
platform: 'networks/lib/x86_64-linux-gnu`G\b��\x7F'

�� - this simbols cause the BSON error for db.system.profile.find and db.currentOp.
For db.system.profile.find I can use enableUtf8Validation = false and avoid the error. But for currentOp I can't use enableUtf8Validation. But I should to use db.currentOp for ops monitoring.
I have next questions:

  1. For the same OS, mongocxx driver, mongodb, mongosh..driver name data can to diff from session to session between c++ client and mongodb. Why?
  2. Can I yet disable UTF8 validation for db.currentOp?
  3. Why mongocxx+mongodb+debian can bourn BSON UTF8 mistake? What reason can be major: driver mongocxx, os debian, mongodb?

答案1

得分: 1

  1. 事实上,我们有一个三级架构:
    mongosh (https://www.mongodb.com/docs/mongodb-shell/) =>
    node.js 驱动程序 (https://github.com/mongodb/node-mongodb-native) =>
    mongodb

  2. Mongosh 和 mongodb 不知道 enableUtf8Validation,但是 node.js 知道。从 mongosh 发送的命令 db.system.profile.find({},{},{enableUtf8Validation: true}) 被传输到 node.js 驱动程序。驱动程序发送到 mongodb 的是清除的 db.system.profile.find()。获得结果 - 任何数据。然后根据 enableUtf8Validation 进行验证或不验证。Node.js 驱动程序是错误的来源 BSONError: BSON 文档中的无效 UTF-8 字符串。不是 mongodb,也不是 mongosh。

  3. 如何为 db.currentOp 修复这个问题?Node.js 驱动程序不允许我们在此命令中发送 enableUtf8Validation。但它可以处理连接字符串中的选项 https://www.mongodb.com/docs/manual/reference/connection-string/。而且它可以在连接对象中获取 enableUtf8Validation https://www.mongodb.com/docs/drivers/node/current/fundamentals/utf8-validation/。所以,这个 URI 格式对我有效:
    mongosh mongodb://user:pass@host:port/db?enableUtf8Validation=false

  4. 为什么坏数据是由 mongocxx 驱动程序 (或 mongodb) 产生的问题仍然存在。但是在连接字符串中使用 enableUtf8Validation=false 可以帮助我们绕过它,用于监视 MongoDB 操作。

英文:

Well, some investigtions have led me to next result.

  1. At fact, we have 3-levels arch:
    mongosh (https://www.mongodb.com/docs/mongodb-shell/) =>
    node.js driver (https://github.com/mongodb/node-mongodb-native) =>
    mongodb

  2. Mongosh and mongodb not know about enableUtf8Validation, but node.js - yes. Command db.system.profile.find({},{},{enableUtf8Validation: true}) from mongosh is transfered to node.js driver. Driver send to mongodb clear db.system.profile.find(). Gets result - any data. And validates it or not (depends by enableUtf8Validation). Node.js driver is source of error BSONError: Invalid UTF-8 string in BSON document. Not mongodb, not mongosh.

  3. How to fix it for db.currentOp? Node.js driver not let us to send enableUtf8Validation with this command. But it can process options in mongodb connection string https://www.mongodb.com/docs/manual/reference/connection-string/. And it can get enableUtf8Validation in connection object https://www.mongodb.com/docs/drivers/node/current/fundamentals/utf8-validation/. So, this uri format works for me:
    mongosh mongodb://user:pass@host:port/db?enableUtf8Validation=false

  4. The question why bad data was bourned by mongocxx driver (or by mongodb) - is still actual. But enableUtf8Validation=false in connstr helps to bypass it for monitoring mongo ops.

huangapple
  • 本文由 发表于 2023年3月9日 17:44:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/75682817.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定