[SERVER-13827] shell no longer validates "toString" field name in document, prints out [object] Created: 04/May/14  Updated: 26/Oct/21  Resolved: 26/Oct/21

Status: Closed
Project: Core Server
Component/s: Shell
Affects Version/s: 2.4.10, 2.6.1-rc1
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Thomas Rueckstiess Assignee: DO NOT USE - Backlog - Platform Team
Resolution: Done Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: ALL
Participants:

 Description   

In earlier versions (tested 2.2.6), the mongo shell refused values (other than functions) for the field named "toString", as it would overwrite the internal method to print the document.

MongoDB shell version: 2.2.6
connecting to: test
> a = {foo: "bar", toString: "test"}
Sun May  4 15:06:52 TypeError: x.toString is not a function src/mongo/shell/utils.js:1027

This is no longer validated in 2.4.x and 2.6.x

MongoDB shell version: 2.4.9
connecting to: test
> a = {foo: "bar", toString: "test"}
[object]
> a
[object]

MongoDB shell version: 2.6.1-rc0
connecting to: test
> a = {foo: "bar", toString: "test"}
[object]
> a
[object]

These documents are displayed with [object] in the shell. This is confusing to users who are not aware of the issue, and also outputs invalid JSON.



 Comments   
Comment by Geert Bosch [ 26/Oct/21 ]

This seems to work as expected with the new mongosh:

test>  a = {foo: "bar", toString: "test"}
{ foo: 'bar', toString: 'test' }

Generated at Thu Feb 08 03:33:00 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.