jeromelebel/MongoHub-Mac

Incorrect saving of data

simoncoulton opened this issue · 15 comments

When attempting to save a simple array in the example below the wrong data is returned from the query. While it displays fine in MongoHub (in the Find tab), retrieving the data from either the console or the PHP driver returns only the first index from an array. If the resulting document contains multiple array objects, then only the first index from all arrays will be shown. This caused me a good hour or two's headache today, and resulted in me going back to the console for all my managing of data, which is a shame as MongoHub is the only native MongoDB GUI (and the PHP based ones just don't cut it).

Saving the following object to the data through the insert tab

{"parts": [1,2,3,4]}

Expected result from db.things.find()

{ "_id" : ObjectId("4f5890ff624df1578936963c"), "parts" : [ 1,2,3,4 ] }

Actual result

{ "_id" : ObjectId("4f5890ff624df1578936963c"), "parts" : [ NumberLong(4) ] }

which translates to this in php

[ 
"_id" => "4f5890ff624df1578936963c", 
"parts" => [ 1 ]
]

Sorry about that. I will try to look at that this week-end. Meanwhile, it might work if you put spaces around the coma.

I'm not able to reproduce this bug... So the document you inserted is just : {"parts": [1,2,3,4]} ? nothing else?

Thanks for replying jerome. Just tried it again without spaces and the issue remains. Occurs in the version that you can download directly (not compile), version 2.4.16[90]. Below is a screenshot from the console, using MongoDB version 2.0.3.

Preview

I will have to make a build with a lot of logs in order to understand what is going on... I'm not able to reproduce this bug...

In your system preferences, open "Language & Text". Can you give a screen shot of the "Language" tab and the "Formats" tab?

Thanks,

Format:

Format

Language:
Language

Sorry about, this issue, but I can't find why you have this problem... Plus I can't reproduce it. Unfortunately I don't have much time. I will try to help you as soon as I can.

Can you try the application MongoHub_test in the download? I did no fix yet (I still don't understand, and I still can't reproduce it), but I added logs into the console. Please, give me the log of the application after reproducing this issue.

Thanks

I've encountered the same issue. I used your MongoHub_test.app to grab the logs you requested.

Here's what's happening.

Via CLI:

> db.examples.findOne()
null
> db.examples.insert({name: "test", items: [{foo: 1}, {foo: 2}, {foo: 3}]})
> db.examples.findOne()
{
        "_id" : ObjectId("4fa3161604924cddfc7f2869"),
        "name" : "test",
        "items" : [
                {
                        "foo" : 1
                },
                {
                        "foo" : 2
                },
                {
                        "foo" : 3
                }
        ]
}

So far so good, MongoHub displays the object properly in the Find tab. If you go to edit the object in MongoHub to add a fourth item to the items array { "foo": 4 }, the log from MongoHub is:

12-05-03 7:35:12.120 PM MongoHub: document string {
  "_id": { "$oid" : "4FA3161604924CDDFC7F2869" },
  "name": "test",
  "items": [
    {
      "foo": 1
    },
    {
      "foo": 2
    },
    {
      "foo": 3
    },
    { "foo": 4 }
  ]
} document data <7b0a2020 225f6964 223a207b 2022246f 69642220 3a202234 46413331 36313630 34393234 43444446 43374632 38363922 207d2c0a 2020226e 616d6522 3a202274 65737422 2c0a2020 22697465 6d73223a 205b0a20 2020207b 0a202020 20202022 666f6f22 3a20310a 20202020 7d2c0a20 2020207b 0a202020 20202022 666f6f22 3a20320a 20202020 7d2c0a20 2020207b 0a202020 20202022 666f6f22 3a20330a 20202020 7d2c0a20 2020207b 2022666f 6f223a20 34207d0a 20205d0a 7d> bson {
    "__sorted_keys__" =     (
        "_id",
        name,
        items
    );
    "_id" = "<MODObjectId: 0x10687e340>";
    items =     (
        "{\n    \"__sorted_keys__\" =     (\n        foo\n    );\n    foo = 1;\n}",
        "{\n    \"__sorted_keys__\" =     (\n        foo\n    );\n    foo = 2;\n}",
        "{\n    \"__sorted_keys__\" =     (\n        foo\n    );\n    foo = 3;\n}",
        "{\n    \"__sorted_keys__\" =     (\n        foo\n    );\n    foo = 4;\n}"
    );
    name = test;
} bson to json {
  "_id": { "$oid" : "4FA3161604924CDDFC7F2869" },
  "name": "test",
  "items": [
    {
      "foo": 1
    },
    {
      "foo": 2
    },
    {
      "foo": 3
    },
    {
      "foo": 4
    }
  ]
}

But, the CLI now returns:

> db.examples.findOne()
{
        "_id" : ObjectId("4fa3161604924cddfc7f2869"),
        "name" : "test",
        "items" : [
                {
                        "foo" : NumberLong(4)
                }
        ]
}

Moreover, if I add a fifth item from the CLI:

> db.examples.update({ "_id": ObjectId("4fa3161604924cddfc7f2869") }, { $pushAll: {"items": [{foo: 5}]} })

I get this result:

{
        "_id" : ObjectId("4fa3161604924cddfc7f2869"),
        "items" : [
                {
                        "foo" : NumberLong(4)
                },
                undefined,
                undefined,
                undefined,
                {
                        "foo" : 5
                }
        ],
        "name" : "test"
}

Although MongoHub still shows the "undefined" items correctly.

MongoDB version is 2.0.4.

This doesn't seem to be a parsing problem (based on the log), and I can't reproduce it with 2.0.1… This is really weird. I will install 2.0.4 to see if I can reproduce this bug.

Thanks for the help

I finally can reproduce it. Sorry, I didn't understand that the problem is not visible in MongoHub. But only in the CLI.

I found the bug, and I have a fix for it. I need to create a test case for it, to make sure it will never happen again.

The data send to mongodb is corrupted. The quick explanation, when an array of value is create, each element of the array needs to have the position index set. When the array contains a structure of objects, the position index is set to 0 for all objects.

I hope to do the test case and the push an update soon.

@jeromelebel Thanks for the quick investigation and fix! This was exceedingly puzzling for a while there.

Fix with 314413b
(based on jeromelebel/MongoObjCDriver@ea50a65 )

Fixed in 2.4.17
Let me know if it works for you.

Yes, this is works for me, now.