{"action":"created","issue":{"url":"https://api.github.com/repos/meteor/meteor/issues/6051","repository_url":"https://api.github.com/repos/meteor/meteor","labels_url":"https://api.github.com/repos/meteor/meteor/issues/6051/labels{/name}","comments_url":"https://api.github.com/repos/meteor/meteor/issues/6051/comments","events_url":"https://api.github.com/repos/meteor/meteor/issues/6051/events","html_url":"https://github.com/meteor/meteor/issues/6051","id":127874318,"number":6051,"title":"inconsistent minimongo insertion","user":{"login":"peonmodel","id":12645203,"avatar_url":"https://avatars0.githubusercontent.com/u/12645203?v=4","gravatar_id":"","url":"https://api.github.com/users/peonmodel","html_url":"https://github.com/peonmodel","followers_url":"https://api.github.com/users/peonmodel/followers","following_url":"https://api.github.com/users/peonmodel/following{/other_user}","gists_url":"https://api.github.com/users/peonmodel/gists{/gist_id}","starred_url":"https://api.github.com/users/peonmodel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/peonmodel/subscriptions","organizations_url":"https://api.github.com/users/peonmodel/orgs","repos_url":"https://api.github.com/users/peonmodel/repos","events_url":"https://api.github.com/users/peonmodel/events{/privacy}","received_events_url":"https://api.github.com/users/peonmodel/received_events","type":"User","site_admin":false},"labels":[{"id":164723116,"url":"https://api.github.com/repos/meteor/meteor/labels/Project:Minimongo","name":"Project:Minimongo","color":"006b75","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-01-21T08:50:14Z","updated_at":"2017-08-16T13:08:40Z","closed_at":null,"body":"minimongo has inconsistent behaviour with regards to undefined\n\ndepending on where the collection is inserted, {a: undefined} will become {} or {a: undefined} or {a:null}\n\n```\n\nif(Meteor.isClient){\n  Test = new Mongo.Collection(null); // local client collection\n  Test.insert({_id: 'client-side-local', a: undefined});\n  var R = Test.findOne('client-side-local');\n  console.log(R);  //  returns {_id: 'client-side-local', a: undefined}  // key 'a' is unchanged\n}\nTest2 = new Mongo.Collection('non-local'); // non-local collection\nTest2.insert({_id: 'client'+Meteor.isClient, a: undefined});  // insert in both client and server side\n\nvar R1 = Test2.findOne('clienttrue');\nconsole.log(R1);  //  returns {_id: 'clienttrue'}  // key 'a' is deleted due to stringify()\nvar R2 = Test2.findOne('clientfalse');\nconsole.log(R2);  // returns {_id: 'clientfalse', a: null}  // key 'a' value undefined is changed to null\n```\n\nshouldn't the local collection consistently delete keys with undefined as value just like how the object will be stringify when sent over the wire\n\nlocal collection already replace File objects into empty object, just like what one expect from stringify, but not for undefined\ne.g.\n\n```\n//Client-side\nTTT = new Mongo.Collection(null);\nvar obj = {\n  file: new File([1, 2, 3, 4, 5], \"name of file.xyz\", {\n    type: 'text/xyz'\n  }),\n  undef: undefined,\n}\nTTT.insert(obj);\nTTT.findOne()  // returns {file: {}, undef: undefined};\nnobj = EJSON.stringify(obj)  // returns \"{\"file\":{}}\"\nEJSON.parse(nobj)  // returns {file:{}}\n```\n"},"comment":{"url":"https://api.github.com/repos/meteor/meteor/issues/comments/322765243","html_url":"https://github.com/meteor/meteor/issues/6051#issuecomment-322765243","issue_url":"https://api.github.com/repos/meteor/meteor/issues/6051","id":322765243,"user":{"login":"hwillson","id":137740,"avatar_url":"https://avatars1.githubusercontent.com/u/137740?v=4","gravatar_id":"","url":"https://api.github.com/users/hwillson","html_url":"https://github.com/hwillson","followers_url":"https://api.github.com/users/hwillson/followers","following_url":"https://api.github.com/users/hwillson/following{/other_user}","gists_url":"https://api.github.com/users/hwillson/gists{/gist_id}","starred_url":"https://api.github.com/users/hwillson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hwillson/subscriptions","organizations_url":"https://api.github.com/users/hwillson/orgs","repos_url":"https://api.github.com/users/hwillson/repos","events_url":"https://api.github.com/users/hwillson/events{/privacy}","received_events_url":"https://api.github.com/users/hwillson/received_events","type":"User","site_admin":false},"created_at":"2017-08-16T13:08:40Z","updated_at":"2017-08-16T13:08:40Z","body":"This is still happening with the latest version of Meteor (1.5.1 as of today). I've created a reproduction here: https://github.com/hwillson/meteor-issue-6051\r\n\r\n`undefined` is not valid JSON, so it's being stripped via EJSON when passed from the client to the server. It's definitely inconsistent to see `undefined` converted to `null` (and saved) when the insert happens on the server. This is happening because Mongo's BSON spec doesn't support `undefined`, so the Mongo node driver is converting `undefined` to `null`, just before saving. We should probably adjust things on the server side to make sure `undefined` values are stripped instead of being converted to `null` and inserted."}}
{"actor":{"display_login":"hwillson"}}