[SERVER-10586] Mongo shell's "null" vs. "undefined" madness continues Created: 20/Aug/13  Updated: 10/Dec/14  Resolved: 24/Aug/13

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

Type: Bug Priority: Major - P3
Reporter: Sean Wilkinson Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Mac OS X 10.8.4 / XCode 4.6.3 / Homebrew updated daily
CentOS 6.4


Issue Links:
Duplicate
duplicates SERVER-6102 Shell displays both 'undefined' and '... Closed
Operating System: ALL
Steps To Reproduce:

For some empty collection "foo", try the following:

> var bar;
> db.foo.save(

{bar: bar}

);

Now, look at the document that was created:

> db.foo.findOne();

{ "_id" : ObjectId("5213ede21269f7d12659b3ea"), "bar" : null }

Oh, okay, so I can isolate such a document to remove it from a dataset, right? WRONG.

> db.foo.find(

{bar: null}

).length()
0
> db.foo.find({bar: {$type: 10}}).length()
0
> db.foo.find({bar: {$type: 6}}).length()
1

Oh, so it was `undefined` all along? That makes sense, except that it lied to me and said it was `null`. So that means the following single line will cause the same problems, won't it?

> db.foo.save(

{bar: undefined}

)

Yes. Yes it will.

Participants:

 Description   

Using the Mongo shell, I am able to create documents whose properties should be `undefined`; these properties are printed to the screen as `null`, however, and therefore they were difficult to remove. The code that I have included below is deceptively simple, but it is distilled from production code. It indicates that there are fundamental problems in the way that MongoDB developers treat JavaScript – either they do not understand it themselves, or they do not expect others to understand it. It's obvious that Mongo's shell breaks with standards-compliant behavior in collection preallocation, for example, but this error is unacceptable. MongoDB's "untyped" nature is very useful for cleaning up messy datasets, as opposed to SQL, but in this case it actually made things much more difficult because I knew there were `null` values in there somewhere, but I couldn't actually find them.



 Comments   
Comment by Daniel Pasette (Inactive) [ 24/Aug/13 ]

duplicate of SERVER-6102

Comment by Sean Wilkinson [ 21/Aug/13 ]

I upgraded to version 2.4.6 on Mac OS X (same platform given above) just now and confirmed that the bug is also present in 2.4.6.

Comment by Sean Wilkinson [ 20/Aug/13 ]

I had previously opened a ticket (https://jira.mongodb.org/browse/DOCS-1747) because I thought there was just a bug in the documentation that listed the BSON type code for `null` incorrectly, but that wasn't the real issue. Instead, the real culprit is the MongoDB shell itself.

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