{"action":"created","issue":{"url":"https://api.github.com/repos/louischatriot/nedb/issues/128","labels_url":"https://api.github.com/repos/louischatriot/nedb/issues/128/labels{/name}","comments_url":"https://api.github.com/repos/louischatriot/nedb/issues/128/comments","events_url":"https://api.github.com/repos/louischatriot/nedb/issues/128/events","html_url":"https://github.com/louischatriot/nedb/pull/128","id":26284671,"number":128,"title":"Upsert should return newly created document with _id","user":{"login":"jasonrhodes","id":159370,"avatar_url":"https://avatars.githubusercontent.com/u/159370?v=3","gravatar_id":"","url":"https://api.github.com/users/jasonrhodes","html_url":"https://github.com/jasonrhodes","followers_url":"https://api.github.com/users/jasonrhodes/followers","following_url":"https://api.github.com/users/jasonrhodes/following{/other_user}","gists_url":"https://api.github.com/users/jasonrhodes/gists{/gist_id}","starred_url":"https://api.github.com/users/jasonrhodes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jasonrhodes/subscriptions","organizations_url":"https://api.github.com/users/jasonrhodes/orgs","repos_url":"https://api.github.com/users/jasonrhodes/repos","events_url":"https://api.github.com/users/jasonrhodes/events{/privacy}","received_events_url":"https://api.github.com/users/jasonrhodes/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2014-01-25T02:19:17Z","updated_at":"2015-07-27T18:56:21Z","closed_at":"2014-02-01T11:42:02Z","pull_request":{"url":"https://api.github.com/repos/louischatriot/nedb/pulls/128","html_url":"https://github.com/louischatriot/nedb/pull/128","diff_url":"https://github.com/louischatriot/nedb/pull/128.diff","patch_url":"https://github.com/louischatriot/nedb/pull/128.patch"},"body":"If { upsert: true } is used on update, and a new document is sucessfully created, it'd be really nice to get that new document returned. Since internally the upsert uses the insert command, it was trivial to hook into the newDoc that insert passes back and send it along to the update callback. This PR includes the code change, updated working tests, and updated README docs. Officially closes #72"},"comment":{"url":"https://api.github.com/repos/louischatriot/nedb/issues/comments/125304932","html_url":"https://github.com/louischatriot/nedb/pull/128#issuecomment-125304932","issue_url":"https://api.github.com/repos/louischatriot/nedb/issues/128","id":125304932,"user":{"login":"dioklecijan","id":4146161,"avatar_url":"https://avatars.githubusercontent.com/u/4146161?v=3","gravatar_id":"","url":"https://api.github.com/users/dioklecijan","html_url":"https://github.com/dioklecijan","followers_url":"https://api.github.com/users/dioklecijan/followers","following_url":"https://api.github.com/users/dioklecijan/following{/other_user}","gists_url":"https://api.github.com/users/dioklecijan/gists{/gist_id}","starred_url":"https://api.github.com/users/dioklecijan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dioklecijan/subscriptions","organizations_url":"https://api.github.com/users/dioklecijan/orgs","repos_url":"https://api.github.com/users/dioklecijan/repos","events_url":"https://api.github.com/users/dioklecijan/events{/privacy}","received_events_url":"https://api.github.com/users/dioklecijan/received_events","type":"User","site_admin":false},"created_at":"2015-07-27T18:56:21Z","updated_at":"2015-07-27T18:56:21Z","body":"Hmm, maybe I am doing something wrong - upsert that resolves to insert returns created doc,\r\nbut upsert that resolves to update do not. However, everything is fine in db file.\r\nMaybe I should not generate custom _id?\r\n\r\n```javascript\r\ndb.bells = new DataStore({ filename: path.join(dbPath, 'bells.db'), autoload: true });\r\nvar _id = \"150b38d1-840f-4286-8398-1724e5557ea8\"; //custom generated\r\ndb.bells.update({ _id: _id }, { _id: _id, enable: false }, { upsert: true },\r\n\tfunction (err, num, doc) {\r\n\t\tconsole.log('typeof doc:' + typeof doc); // => object (ok), num=1, err=null\r\n\r\n\t\tdb.bells.update({ _id: _id }, { _id: _id, enable: true }, { upsert: true },\r\n\t\t\tfunction (err, num, doc2) {\r\n\t\t\t\tconsole.log('typeof doc2:' + typeof doc2); // => undefined (!ok), num=1, err=null\r\n\t\t\t});\r\n\t});\r\n```\r\n\r\n"}}