{"action":"created","issue":{"url":"https://api.github.com/repos/strongloop/loopback-connector-mongodb/issues/92","labels_url":"https://api.github.com/repos/strongloop/loopback-connector-mongodb/issues/92/labels{/name}","comments_url":"https://api.github.com/repos/strongloop/loopback-connector-mongodb/issues/92/comments","events_url":"https://api.github.com/repos/strongloop/loopback-connector-mongodb/issues/92/events","html_url":"https://github.com/strongloop/loopback-connector-mongodb/pull/92","id":56761482,"number":92,"title":"Feature/optmized find or create","user":{"login":"clarkorz","id":3261477,"avatar_url":"https://avatars.githubusercontent.com/u/3261477?v=3","gravatar_id":"","url":"https://api.github.com/users/clarkorz","html_url":"https://github.com/clarkorz","followers_url":"https://api.github.com/users/clarkorz/followers","following_url":"https://api.github.com/users/clarkorz/following{/other_user}","gists_url":"https://api.github.com/users/clarkorz/gists{/gist_id}","starred_url":"https://api.github.com/users/clarkorz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/clarkorz/subscriptions","organizations_url":"https://api.github.com/users/clarkorz/orgs","repos_url":"https://api.github.com/users/clarkorz/repos","events_url":"https://api.github.com/users/clarkorz/events{/privacy}","received_events_url":"https://api.github.com/users/clarkorz/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/strongloop/loopback-connector-mongodb/labels/%23community%20contribution","name":"#community contribution","color":"D4AF37"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-02-06T02:24:03Z","updated_at":"2015-02-06T02:27:53Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/strongloop/loopback-connector-mongodb/pulls/92","html_url":"https://github.com/strongloop/loopback-connector-mongodb/pull/92","diff_url":"https://github.com/strongloop/loopback-connector-mongodb/pull/92.diff","patch_url":"https://github.com/strongloop/loopback-connector-mongodb/pull/92.patch"},"body":"1. require strongloop/loopback-datasource-juggler#419 to be merged first\r\n2. cause [one test fail](https://github.com/strongloop/loopback-datasource-juggler/blob/master/test/relations.test.js#L1465) due to id generation, see below\r\n\r\nThe test fail because the order of pictures are different. The *Example* picture is linked to the author, which calls `findOrCreate()`, but other two don't.\r\n\r\n1. By default, *mongodb-driver* will take care of `_id` (generate in client process), but `findAndModify` command is different, when it results an upsert, the `_id` is generated by mongodb server(generate in server process).\r\n2. the connector sorts query by `_id` field, the result might be different among environments.\r\n\r\nAny thoughts?"},"comment":{"url":"https://api.github.com/repos/strongloop/loopback-connector-mongodb/issues/comments/73172926","html_url":"https://github.com/strongloop/loopback-connector-mongodb/pull/92#issuecomment-73172926","issue_url":"https://api.github.com/repos/strongloop/loopback-connector-mongodb/issues/92","id":73172926,"user":{"login":"clarkorz","id":3261477,"avatar_url":"https://avatars.githubusercontent.com/u/3261477?v=3","gravatar_id":"","url":"https://api.github.com/users/clarkorz","html_url":"https://github.com/clarkorz","followers_url":"https://api.github.com/users/clarkorz/followers","following_url":"https://api.github.com/users/clarkorz/following{/other_user}","gists_url":"https://api.github.com/users/clarkorz/gists{/gist_id}","starred_url":"https://api.github.com/users/clarkorz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/clarkorz/subscriptions","organizations_url":"https://api.github.com/users/clarkorz/orgs","repos_url":"https://api.github.com/users/clarkorz/repos","events_url":"https://api.github.com/users/clarkorz/events{/privacy}","received_events_url":"https://api.github.com/users/clarkorz/received_events","type":"User","site_admin":false},"created_at":"2015-02-06T02:27:52Z","updated_at":"2015-02-06T02:27:52Z","body":"> The *Example* picture is linked to the author, which calls `findOrCreate()`, but other two don't.\r\n\r\nI think this is the problem. `HasManyThrough#create()` calls `ThroughModel.create()`, not `ThroughModel.findOrCreate()`."}}