Robomongo: Robomongo doesn't understand json "comments" when inserting from UI

Created on 25 Sep 2013  ·  5Comments  ·  Source: Studio3T/robomongo

I have the following json:

{
    "dolphins": "Whether the oceans will contain dolphins.",
    "dolphins": false,

    "jellyfish": "How many jellyfish are present. Zero to disable jellyfish.",
    "jellyfish": 7000
}

When I insert it into my collection via "Insert Document UI", it saves as

{
    "_id" : ObjectId("5243311918f524ca2bdfc738"),
    "dolphins" : "Whether the oceans will contain dolphins.",
    "dolphins" : false,
    "jellyfish" : "How many jellyfish are present. Zero to disable jellyfish.",
    "jellyfish" : 7000
}

Its not correct behavior.

BUT when I insert the same document via Robomongo shell as db.test.insert({...}), it saves correctly:

{
    "_id" : ObjectId("5243310b90e5e7cf448c86d2"),
    "dolphins" : false,
    "jellyfish" : 7000
}
bug

Most helpful comment

Is this related to the problem where comments such as:
/* 1 */
(Which are generated by RoboMongo itself btw)
cause a problem when trying to mass-insert records?

All 5 comments

Nice! Really interesting :)

According to the current JSON spec, there is no support for comments: http://www.json.org.

The behaviour difference in this example is because:

  • When inserting from the shell (or in JavaScript) the JSON data structure will be flattened so there is only one value per unique key. Duplicate keys in a Javascript object are not supported, so the comment hack here presumes the last value per unique key will be the one used.
  • When inserting via C++ (as used by the Robomongo Insert Document UI) it is possible to represent duplicate keys in a BSON object (and valid to save this to the server). So the full document is saved including duplicate "comment" fields.

Problems will arise when trying to query the documents with duplicate keys from most drivers or the standard mongo shell, as the typical representation of a BSON document as a hash or dictionary does not provide predictable results with duplicate keys.

So the "correct" fix is probably for users to not use JSON "comments" hack as this is non-standard and makes some assumptions on how duplicate keys are handled. A friendlier fix might be to implement the expected behaviour of "last value wins" when parsing JSON. Seems like Qt's JSON parser should already be enforcing this (if it's even applicable here): http://qt-project.org/doc/qt-5.1/qtcore/json.html.

Cheers,
Stephen

This is another consistency issue for the JSON validation used in the Robomongo Insert Document UI versus mongo shell (eg #335, #448). Not sure if we should rename either this issue or #448 to be specific to matching mongo validation .. or would be better creating a new ticket linking to the current differences (which are adding up!).

Is this related to the problem where comments such as:
/* 1 */
(Which are generated by RoboMongo itself btw)
cause a problem when trying to mass-insert records?

yes

Was this page helpful?
0 / 5 - 0 ratings