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

feat(JMongosh): don't convert object from Java to JS and back if results are returned directly to user #1077

Merged

Conversation

kornilova203
Copy link
Collaborator

@kornilova203 kornilova203 commented Aug 24, 2021

A simple fix but it needs to access private fields Cursor._cursor and Cursor._transform

It sets resultsUsedInScript flag to false right before cursor is returned to user.
When resultsUsedInScript is false, internal Java cursor doesn't convert Java objects to JS

@@ -1,3 +1,3 @@
{ "acknowledged": true, "insertedId": "UNKNOWN" }
true
[ { "_id": <ObjectID>, "a": 1, "objectId": <ObjectID>, "maxKey": {"$maxKey": 1}, "minKey": {"$minKey": 1}, "binData": {"$binary": {"base64": "MTIzNA==", "subType": "10"}}, "date": {"$date": {"$numberLong": "1355875200000"}}, "isoDate": {"$date": {"$numberLong": "1355875200000"}}, "numberInt": 24, "timestamp": {"$timestamp": {"t": 100, "i": 0}}, "undefined": null, "null": null, "uuid": <UUID> } ]
[ { "_id": <ObjectID>, "a": 1, "objectId": <ObjectID>, "maxKey": {"$maxKey": 1}, "minKey": {"$minKey": 1}, "binData": {"$binary": {"base64": "MTIzNA==", "subType": "10"}}, "date": {"$date": {"$numberLong": "1355875200000"}}, "isoDate": {"$date": {"$numberLong": "1355875200000"}}, "numberInt": 24, "timestamp": Timestamp{value=429496729600, seconds=100, inc=0}, "undefined": null, "null": null, "uuid": <UUID> } ]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit curious – isn’t the output supposed to be EJSON (just basing off $maxKey, $minKey, $binary etc.)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually yes, it should.
I can fix it but then I'll need to find a better way to check if values were converted to JS or not.
I'll do it but later

@addaleax addaleax merged commit b5ed69e into mongodb-js:main Aug 24, 2021
@kornilova203 kornilova203 deleted the JMongosh/avoid-extra-object-conversion branch August 24, 2021 15:38
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

Successfully merging this pull request may close these issues.

2 participants