Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_id Type being changed to int32 after editing via json if it was initially inserted as int64 #2960

Closed
abdullahbaa5 opened this issue Apr 7, 2022 · 7 comments

Comments

@abdullahbaa5
Copy link

Only since the latest GUI Update: When you edit the document via json editor, if the _id field type was int64, changing any field in the Json View Editor will cause the _id field type to change to int32.

When viewing the document via JSON Viewer the int64 _id field is being represented like:
{
"_id": 3
}

however in the previous version you could specify that it is int64 with this:
{
"_id": {
"$numberLong": "3"
}
}

if you try to specify it with $numberLong in the latest compass it will just give you error that it is not possible to edit an immutable field _id.

Environment

  • compass version: 1.31.1
  • OS: Windows 10

Possible Solution

Works fine in previous version that does not have the latest UI update

@ToxicLand
Copy link

Same issue here

@addaleax
Copy link
Contributor

addaleax commented Apr 7, 2022

@ToxicLand @abdudsoul Can you share screenshots of what exactly you are doing? In particular, the error message and the before/after state in the JSON viewer?

@ToxicLand
Copy link

ToxicLand commented Apr 8, 2022

@addaleax Sure. This first image shows that in the default view, _id type is Int64. https://i.imgur.com/uVVdUqV.jpg
The second one shows the value of region, this is what I'm going to change to something different, using the json editor view (any change will trigger the bug) https://i.imgur.com/lYJqoZD.jpg
The third image shows that the type of _id has changed to Int32. This causes problems with my application. https://i.imgur.com/mUTsyIK.jpg
The last image shows the error I get when I try to change it back to Int64. https://i.imgur.com/pA8X8GA.jpg
Only way to fix this is to downgrade Compass and then change it manually.
I didn't post a before-after from the JSON viewer, because it only shows "_id": 2, before and after.

@addaleax
Copy link
Contributor

addaleax commented Apr 8, 2022

Thank you for bringing this up! I’ve opened https://jira.mongodb.org/browse/COMPASS-5711 (and the related, also regressed https://jira.mongodb.org/browse/COMPASS-5710) to track this.

addaleax added a commit that referenced this issue Apr 11, 2022
Fix various EJSON handling bugs by aligning our EJSON handling
a bit more closely. This fixes regressions introduced by me
in e654e1d (COMPASS-5710, COMPASS-5711 aka
#2960) and another
long-standing export bug (COMPASS-4694).

Specifically, use `{ relaxed: false }` when parsing values
into `HadronDocument`, and use `{ relaxed: false }` but
undo the strict conversion for `$numberInt` and `$numberDouble`.
This is a mode that we may eventually want to upstream
into the Node.js driver’s `bson` package.
addaleax added a commit that referenced this issue Apr 12, 2022
Fix various EJSON handling bugs by aligning our EJSON handling
a bit more closely. This fixes regressions introduced by me
in e654e1d (COMPASS-5710, COMPASS-5711 aka
#2960) and another
long-standing export bug (COMPASS-4694).

Specifically, use `{ relaxed: false }` when parsing values
into `HadronDocument`, and use `{ relaxed: false }` but
undo the strict conversion for `$numberInt` and `$numberDouble`.
This is a mode that we may eventually want to upstream
into the Node.js driver’s `bson` package.
@addaleax
Copy link
Contributor

This should be fixed in the next release, thanks for reporting!

@ToxicLand
Copy link

ToxicLand commented Apr 15, 2022

@addaleax I just installed the latest release that fixed the type changing itself upon modifying the document, but if I want to change existing (affected by the bug) documents from Int32 to Int64 (like how it is for the rest of the documents) using the default view, I still get a "Plan executor error during findAndModify :: caused by :: Performing an update on the path '_id' would modify the immutable field '_id'". Currently the workaround for this is to switch to the json editor, and apply "_id": {"$numberLong": "3"}.

@addaleax
Copy link
Contributor

@ToxicLand Yeah, that is honestly kind of expected, even if it might not be obvious why 😕 The table and “normal” document view use findOneAndUpdate for changing a document, where _id is really immutable. Due to the way the JSON view/editing works, we can’t (easily) do the same there, we use findOneAndReplace instead.

This does come with concrete downsides – for example, if the document was changed by something else in the background, this will still replace the entire document with whatever was in the JSON editor, rather than accounting for those other updates. The other editing modes don’t have this issue. I’ve opened https://jira.mongodb.org/browse/COMPASS-5753 for us to talk about this a bit further, but I can’t promise that we’ll make any changes here per se.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants