javascriptmongodbdatagripnavicat

Why the same mongodb query behaves inconsistently between different client?


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?


Solution

  • 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