首先,让我们以此简单查询为示例:
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?
发布评论
评论(1)
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