[SERVER-12601] Shell REPL doesn't properly print literal objects containing an _id field Created: 04/Feb/14  Updated: 11/Feb/14  Resolved: 11/Feb/14

Status: Closed
Project: Core Server
Component/s: Shell
Affects Version/s: 2.5.5
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Ben Becker Assignee: Unassigned
Resolution: Done Votes: 0
Labels: 26qa, shell
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: ALL
Participants:

 Description   

The following examples illustrate strange behavior with the shell REPL's handling of objects with an _id field. Note that all of these should be valid, and should print the object itself:

> {_id:1}
1
> {'_id':1}
2014-02-04T11:51:48.382-0500 SyntaxError: Unexpected token :
> {"_id":1}
2014-02-04T11:51:54.014-0500 SyntaxError: Unexpected token :
> var a = {"_id":1}
> a
{ "_id" : 1 }
> var a = {_id:1}
> a
{ "_id" : 1 }



 Comments   
Comment by Ben Becker [ 11/Feb/14 ]

exi, many thanks for pointing this out.

I had erroneously assumed that object literals could be evaluated just like other literal types (e.g. array, regex, string, number, etc.).

Comment by Reno Reckling [ 11/Feb/14 ]

This is not a bug but a "feature" of javascript.
Top level expressions like the object notation have to be enclosed in parenthesis.

> ({"_id":4})
{ "_id" : 4 }

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