[SERVER-6102] Shell displays both 'undefined' and 'null' type as 'null' Created: 15/Jun/12  Updated: 03/Apr/19  Resolved: 11/Nov/15

Status: Closed
Project: Core Server
Component/s: Shell
Affects Version/s: None
Fix Version/s: 3.2.0-rc3

Type: Bug Priority: Major - P3
Reporter: siddharth.singh@10gen.com Assignee: Jonathan Reams
Resolution: Done Votes: 5
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by SERVER-5974 distinct returns duplicate values Closed
Documented
is documented by DOCS-6579 Undefined now maps to undefined in sh... Closed
Duplicate
duplicates SERVER-19503 Javascript object serialization proce... Closed
is duplicated by SERVER-9817 Collection options with value of BSON... Closed
is duplicated by SERVER-10586 Mongo shell's "null" vs. "undefined" ... Closed
is duplicated by SERVER-7731 undefined is converted to null in jav... Closed
Related
related to SERVER-19171 Shell does not always use extended JS... Closed
is related to SERVER-7104 jsonString has incorrect output on un... Closed
is related to SERVER-2426 Convert/print bson undefined type as ... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: Build C (11/20/15)
Participants:

 Description   

mongo shell should display these types correctly and not display both of them as null. Please see SERVER-5974 for more background where distinct command would was showing up as [null,null] in the shell as the shell wouldn't differentiate between these two types.



 Comments   
Comment by Githook User [ 11/Nov/15 ]

Author:

{u'username': u'jbreams', u'name': u'Jonathan Reams', u'email': u'jbreams@mongodb.com'}

Message: SERVER-6102 Deserialize BSON undefined as JS undefined
Branch: master
https://github.com/mongodb/mongo/commit/338f764be00c3a5cef387dd1ba8a56671fc4ef6b

Comment by Thomas Rueckstiess [ 27/Jun/15 ]

ping.

The way the shell handles "undefined" is just extremely confusing:

> a = undefined
> a
> {a: undefined}
>
> {a: undefined, b: 3}
2015-06-27T23:51:28.179+1000 E QUERY    SyntaxError: Unexpected token :
> var doc = {a: undefined, b: 3}
> doc
{ "a" : undefined, "b" : 3 }
> db.foo.insert({"undef": undefined})
WriteResult({ "nInserted" : 1 })
> db.foo.find({"undef": {$exists: true}})
{ "_id" : ObjectId("558eaa95250f587c27e993a6"), "undef" : null }
> db.foo.find({"undef": {$type: 6}})
{ "_id" : ObjectId("558eaa95250f587c27e993a6"), "undef" : null }

Note the parsing error when the document with value undefined is not assigned to a variable, but it works when assigning it to a variable.

Comment by Mathias Stearn [ 03/Jul/12 ]

This is not just a display value, the shell actually loads BSON undefined as null. printjson shows undefined as undefined

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