[SERVER-2426] Convert/print bson undefined type as javascript undefined, not null Created: 27/Jan/11 Updated: 11/Nov/15 Resolved: 11/Nov/15 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | JavaScript, Shell |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Minor - P4 |
| Reporter: | David Hu | Assignee: | DO NOT USE - Backlog - Platform Team |
| Resolution: | Duplicate | Votes: | 2 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||||||||||
| Backwards Compatibility: | Fully Compatible | ||||||||||||||||||||
| Participants: | |||||||||||||||||||||
| Description |
|
This snippet shows how an "Undefined" (0x06) BSON value may get stored into the database. use tempDB; ); ); // expects one document but actually returns zero documents. |
| Comments |
| Comment by Jonathan Reams [ 11/Nov/15 ] |
|
Duplicate of |
| Comment by Eliot Horowitz (Inactive) [ 31/Jan/11 ] |
|
Agree it has to be consistent, but there are some reasons to keep undefined. So the real task is clearly laying out all js conversions and making sure its consistent. |
| Comment by David Hu [ 28/Jan/11 ] |
|
If you retrieve a document containing "undefined" BSON values and save it back into the collection, those "undefined" BSON will values get converted to "null" BSON values. Here's an example: > db.temp.save({_id:1, b:{}.undefinedField}); > doc.c = "str"; In v8_wrapper's mongoToV8Element function, "undefined" elements (0x06) get converted to v8::Null(). However, the v8ToMongoElement function converts v8 "undefined" elements to BSON "undefined" elements. |
| Comment by Scott Hernandez (Inactive) [ 28/Jan/11 ] |
|
It is even easier than that. > printjson( {a:undefined}) undefined is a valid value in javascript, and in bson. What is the motivation for removing it? And why set it to null? It seems like if a field value is undefined then the field should be skipped, not set to null. |