[SERVER-61234] JS object-based types are not properly auto-serialized when directly returned by server-side JS functions Created: 04/Nov/21 Updated: 29/Oct/23 Resolved: 26/Mar/22 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | JavaScript |
| Affects Version/s: | None |
| Fix Version/s: | 6.0.0-rc0, 5.0.10, 4.4.16 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Kevin Pulo | Assignee: | Justin Seyster |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | query-director-triage | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Attachments: |
|
||||||||||||||||||||||||
| Issue Links: |
|
||||||||||||||||||||||||
| Backwards Compatibility: | Minor Change | ||||||||||||||||||||||||
| Operating System: | ALL | ||||||||||||||||||||||||
| Backport Requested: |
v6.0, v5.3, v5.0, v4.4, v4.2
|
||||||||||||||||||||||||
| Sprint: | QE 2021-12-13, QE 2021-12-27, QE 2022-01-10, QE 2022-04-04, QE 2022-02-07, QE 2022-02-21, QE 2022-03-07, QE 2022-03-21, QE 2022-01-24 | ||||||||||||||||||||||||
| Participants: | |||||||||||||||||||||||||
| Linked BF Score: | 14 | ||||||||||||||||||||||||
| Description |
|
This mostly affects the $function or $accumulator aggregation operators. (I expect MapReduce and $where are similarly affected.) When these types are embedded within a document (object), they are fine. But when directly returned by a function, they are incorrectly serialized as an empty BSON object:
The specific (current) types affected by this are:
I've attached a test script The main problems are two-fold:
For example, this is the patch required to fix ObjectId/jstOID (evergreen patch build):
The other types almost certainly require correspondingly similar adjustments. There is another consideration for any future types that may be represented as a JS object, but without their own BSON type, ie. serialized to a BSON Object representation, eg. { $foo: { ... } }. Any such types will still fail to serialize if they are the top-level object (but will work fine if they are a field inside another BSON object). One way to fix this (without needing invasive restructuring of ValueWriter/ObjectWrapper) might be to adjust ValueWriter::toBSON() to nest the object inside a parent object, for example, something like as shown below (evergreen patch build). However, this may have some other adverse effects (eg. reducing the effective maximum BSON depth by 1, possibly lowering performance, etc).
|
| Comments |
| Comment by Githook User [ 28/Jun/22 ] |
|
Author: {'name': 'Justin Seyster', 'email': 'justin.seyster@mongodb.com', 'username': 'jseyster'}Message: (cherry picked from commit 88162ec9f40f08fcf4dd31d24aa2532744e13dee) |
| Comment by Githook User [ 28/Jun/22 ] |
|
Author: {'name': 'Justin Seyster', 'email': 'justin.seyster@mongodb.com', 'username': 'jseyster'}Message: (cherry picked from commit 88162ec9f40f08fcf4dd31d24aa2532744e13dee) |
| Comment by Githook User [ 26/Mar/22 ] |
|
Author: {'name': 'Justin Seyster', 'email': 'justin.seyster@mongodb.com', 'username': 'jseyster'}Message: |
| Comment by Ethan Zhang (Inactive) [ 07/Feb/22 ] |
|
I am sending this to justin.seyster to take a look |