Robomongo: JSON validator not accepting valid document

Created on 8 Jul 2015  路  14Comments  路  Source: Studio3T/robomongo

I am using Doctrine ODM which creates a "special" reference type if you make use of Single Collection inheritance

These documents can not be edited with robomongo (version 0.8.5 on Mac).

To map Mongo Documents to Model Objects (classes) there is a field added to each reference. Which can be named whatever you want to. In this case I used "type".

When I edit the document with robomongo the validation fails until I remove this special field.

It would be great if there was only warning, but I could submit the data to MongoDB anyhow.

Example Document:

{
    "_id" : ObjectId("559d687f6325213e2c0041a8"),
    "name" : "testobject"
    "user" : {
        "$ref" : "BaseUser",
        "$id" : ObjectId("5588016528c806bf040041a7"),
        "$db" : "wbu",
        "type" : "admin"
    }
}
bug major

Most helpful comment

No matter how you call it. This annoying "feature/bug/lunacy" costs us quite a lot of time and in combination with Studio 3T "feature/bug/lunacy" (that destroys references in Doctrine documents) introduces frequent bugs in production. What a suite of tools! I am using Compass but it is barely usable as well. Pretty sad story.

All 14 comments

Try to preplace ObjectId(<ID>) with $oid: <ID>.

The problem is not that it doesn't accept manually written json. Sometimes I open JSON in Robomongo (edit document), change nothing and still can't save. It seems to be related to linebreaks in strings.

As mentioned in #968, as a temporary workaround you can put all extra fields above db ref fields:

{
    "_id" : ObjectId("559d687f6325213e2c0041a8"),
    "name" : "testobject",
    "user" : {
        "type" : "admin",
        "$ref" : "BaseUser",
        "$id" : ObjectId("5588016528c806bf040041a7"),
        "$db" : "wbu"
    }
}

Keeps failing for me as well. Changing nothing in the document results in the error. Impossible to edit the document very frequently.

I'm struggling very often with this and I experienced the same behaviour (Robomongo 0.8,0.8.5, 0.9.0).

Doctine/Mongo saves a reference in a structure like this

{
    "ref" : {
        "$ref" : "someobject",
        "$id" : ObjectId("559d687f6325213e2c0041a8"),
        "$db" : "database",
        "_doctrine_class_name" : "classes\\someobject"
    }
}

You cannot save this after opening in editor.
_"Unable to parse JSON: Expecting 24 hex digits: 5759034e30609be136caaaa, at (4, 52)."_
And the colon at the end of the "$id" line will be highlighted

If I move the the bottom line to top instead, I can save the document

{
    "ref" : {
        "_doctrine_class_name" : "classes\\someobject",
        "$ref" : "someobject",
        "$id" : ObjectId("559d687f6325213e2c0041a8"),
        "$db" : "database"

    }
}

If you have more refs in a document you have a lot of additional work to turn the order.
The Problem is that Doctine will turn this "workarround" back again by saving the document.
For me it is a lot of work with the workarround. I'm thinking of writing own code to handle my changes in future.

Hi guys, agree and sorry to hear that this problem causes you lots of pain. I took a look at the code and did some testing. Seems like the problem (exception) is caused by not directly from Robomongo code but from mongo code in "/src/mongo/bson/json.cpp" mongo::fromJson() function which creates BSON obj. Unfortunately, I did not see a quick solution, seems like parser does not like the order when DBRefs are used. The JSON parsing algorithm of mongo::fromJson() function should be investigated to understand/fix the problem.

I am tagging this as major, hopefully we will investigate this problem after releasing some critical features like Replica Sets and Export/Import.

And as another workaround solution, you can try inserting from robomongo-shell:

Next Actions:

  • A possible fix (as an alternative to investigating & fixing the problem directly in mongo::fromJSON()) might be using ScriptEngine->exec("db.collection.update()...") in MongoClient::saveDocument() instead of _dbclient->update() for the cases when JSON validation fails due to DBRefs (and the same idea can be applied for insert document operation)

@Any news on this issue? i am on the same boat...
what about an option to disable validation?

this is the json, just for reference

```javascript
{
"_id" : ObjectId("58920ccc6e955208bd4ae929"),
"sizes" : [
12,
12,
12
],
"uid" : "blocco-0",
"title" : "Line Chart",
"blockContents" : [
{
"$ref" : "BaseBlockContent",
"$id" : ObjectId("58920ccc6e955208bd4ae928"),
"$db" : "dash",
"type" : "line_chart"
}
],
"createdAt" : ISODate("2017-02-01T16:29:00.000Z"),
"updatedAt" : ISODate("2017-02-01T16:29:00.000Z"),
"type" : "base_block"
}

Hi @stormsson,
I have reproduced your problem and I was able to insert the document with the workaround solution I suggested in previous comment https://github.com/paralect/robomongo/issues/912#issuecomment-257549753.

So shortly, you may use db.collection.insert(...) on Robomongo shell instead of "insert document" window until we provide a permanent solution for this problem.
(Unfortunately no permanent fix yet, we were snowed under developing/releasing Robomongo with replica set support and many other improvements which was released yesterday BTW.)

And thanks also for your suggestion about disabling validation, but the root cause of the problem is not related to Robomongo validation, it is mongo functions rejecting this JSON. (You may see details of the problem in my comment https://github.com/paralect/robomongo/issues/912#issuecomment-257549753). Our mongo dependencies will be updated from mongo 3.2 to 3.4. I believe this upgrade will fix this and similar problems.

Please let us know if the workaround works for you.

Thank you, i didn't notice the suggestion; it is a bit more complex when editing fields, since you need to re-create the query by hand.

What about a right click > "copy edit query to clipboard" option when right-clicking on the record?

Yes, that also sounds good. We will consider. Thanks a lot.

I had the same issue, i.e. unable to insert a json via Robo 3T, when the JSON payload contains properties called "$ref", work around to insert the JSON payload via Robo 3T insert script worked.

This is not a bug. The proposed JSON document is invalid.

But it would be good if Robo3T offered a way to display valid JSON which it currently seems unable to do.

I would close this ticket as the document provided is not valid JSON.

This is not a bug. The proposed JSON document is invalid.

But it would be good if Robo3T offered a way to display valid JSON which it currently seems unable to do.

I would close this ticket as the document provided is not valid JSON.

How is it not a valid JSON document? In the examples above, you could literally click edit document, and click save immediately and it would not work.

This is one of the most annoying bugs in the otherwise very useful software.

No matter how you call it. This annoying "feature/bug/lunacy" costs us quite a lot of time and in combination with Studio 3T "feature/bug/lunacy" (that destroys references in Doctrine documents) introduces frequent bugs in production. What a suite of tools! I am using Compass but it is barely usable as well. Pretty sad story.

Was this page helpful?
0 / 5 - 0 ratings