[SERVER-60770] $function does not accept native functions Created: 18/Oct/21 Updated: 06/Dec/22 |
|
| Status: | Backlog |
| Project: | Core Server |
| Component/s: | None |
| Affects Version/s: | 5.0.3 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Minor - P4 |
| Reporter: | Wojciech Waga | Assignee: | Backlog - Query Execution |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | neweng | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Attachments: |
|
| Assigned Teams: |
Query Execution
|
| Operating System: | ALL |
| Participants: |
| Description |
|
For the following pipeline:
the "$function" operator does not seem to work correctly and returns a rather hard to decipher error: "MongoServerError: SyntaxError: missing ] after element list" . JSON.parse is a widely used function and certainly a valid one for lang type "js". The problem here is that instead of treating functions as first-class functions (the way Javascript does it) and being able to pass them as an argument Mongo seems to call toString() method instead. For this particular function calling toString() returns: "function parse() { [native code] }" which inserted into the pipeline as body yields the same error. There is a possible workaround for this:
Here the server has no issues with calling native code function. Looks like little extra logic should be able to handle such cases even if hard to fix in the core. Making the error message more readable would certainly help as well. |
| Comments |
| Comment by Kyle Suarez [ 09/Nov/21 ] | |||||||||||||||||||
|
Adding this ticket to the backlog, to examine the function parsing code and improve the error message here to be more clear. Please continue to watch this ticket for updates. | |||||||||||||||||||
| Comment by Joe Kanaan [ 04/Nov/21 ] | |||||||||||||||||||
|
Moving this to Query Execution for review. | |||||||||||||||||||
| Comment by Edwin Zhou [ 03/Nov/21 ] | |||||||||||||||||||
|
Thanks for your report. I've been able to reproduce this issue and while I believe the workaround is a sound solution, I agree that we can clarify the error message and also improve the documentation around $function. I've uploaded repro.js
These are the respective results:
I will pass this along to the query team to further investigate. Best, |