为什么在不同的客户端之间相同的MongoDB查询行为不一致?

发布于 2025-02-11 03:57:05 字数 683 浏览 0 评论 0 原文

首先,让我们以此简单查询为示例:

ObjectID('62663DEF4E578B0A1CB482C5')。valueof();

datagrip v2021.3.1:输出 {“ $ oid”:“ 62663DEF4E578B0A1CB482C5”}

在Navicat中输出MongoDB V16.0.14: 62663DEF4E578B0A1CB482C5

在蒙古1.5.0中输出: ObjectID(“ 62663DEF4E578B0A1CB482C5”)

第二,带有 type> type> typeof 运算符,即: typeof ObjectID('62663DEF4E578B0A1CB482C5')。valueof(); ,我们可以看到输出的数据类型。它们在Datagrip和Mongosh中都是对象,但 String 在Navicat的MongoDB中。

这是一个显而易见的问题,当开发人员编写复杂的查询时,我相信必须为类似问题筹集门票(但我还没有找到)。

为什么会这样?这可能是由于每个客户端集成了不同的MongoDB驱动程序版本,但我四处搜索,但没有找到任何可靠的官方文件。谁能为此提供帮助吗?

firstly, let's take this simple query as example:

ObjectId('62663def4e578b0a1cb482c5').valueOf();

output in DataGrip v2021.3.1:
{"$oid": "62663def4e578b0a1cb482c5"}

output in Navicat for MongoDB v16.0.14:
62663def4e578b0a1cb482c5

output in mongosh 1.5.0:
ObjectId("62663def4e578b0a1cb482c5")

secondly, with typeof operator, i.e.:
typeof ObjectId('62663def4e578b0a1cb482c5').valueOf();, we can see the data type of the output. they are object in both DataGrip and Mongosh but string in Navicat for MongoDb.

This is an obvious issue and problematic when developers write complex queries, I believe there must be tickets raised for similar issue(but i haven't found one).

Why it it like this? It could be due to different mongoDB driver version integrated in each client but I searched around and haven't found any solid official documents. Could anyone help on this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

归属感 2025-02-18 03:57:05

DataGrip中使用的Mongosh和MongodB JDBC驱动程序具有相同的核心,因此它们应该非常相似(您的示例表明。 {“ $ oid”:“ 62663DEF4E578B0A1CB482C5”} 只是objectid的表示类型)。

我不记得Navicat使用了什么。我可能会猜想他们有一个用于MongoDB Nodejs驱动程序的包装器,或者直接使用了名为Mongo的旧壳。

我要说的是, mongosh 应该具有最正确的行为,因为它是最近开发的新外壳。如果您认为这种行为是不正确的,请尝试在Mongosh问题中创建问题,

如果您认为Navicat的行为不正确,请尝试在其错误跟踪器中创建问题

mongosh and MongoDB JDBC driver that is used in DataGrip have the same core so they should be very similar (and your examples show that. {"$oid": "62663def4e578b0a1cb482c5"} is just json representation of ObjectId type).

I don't remember what Navicat uses. I might guess that they have a wrapper for MongoDB NodeJS driver or they directly use old shell called mongo.

I would say that mongosh should have the most correct behaviour since it's a new shell that was developed very recently. If you think that this behaviour is incorrect try to create an issue in mongosh issue tracker https://jira.mongodb.org/projects/MONGOSH/issues/

If you think that behaviour of Navicat is incorrect, try to create an issue in their bug tracker

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文