{"action":"created","issue":{"url":"https://api.github.com/repos/seanemmer/mongoose-seed/issues/28","repository_url":"https://api.github.com/repos/seanemmer/mongoose-seed","labels_url":"https://api.github.com/repos/seanemmer/mongoose-seed/issues/28/labels{/name}","comments_url":"https://api.github.com/repos/seanemmer/mongoose-seed/issues/28/comments","events_url":"https://api.github.com/repos/seanemmer/mongoose-seed/issues/28/events","html_url":"https://github.com/seanemmer/mongoose-seed/issues/28","id":338323778,"node_id":"MDU6SXNzdWUzMzgzMjM3Nzg=","number":28,"title":"How to Dynamically Reference in a Seeder an Object Id of a Document?","user":{"login":"superKalo","id":2548061,"node_id":"MDQ6VXNlcjI1NDgwNjE=","avatar_url":"https://avatars2.githubusercontent.com/u/2548061?v=4","gravatar_id":"","url":"https://api.github.com/users/superKalo","html_url":"https://github.com/superKalo","followers_url":"https://api.github.com/users/superKalo/followers","following_url":"https://api.github.com/users/superKalo/following{/other_user}","gists_url":"https://api.github.com/users/superKalo/gists{/gist_id}","starred_url":"https://api.github.com/users/superKalo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/superKalo/subscriptions","organizations_url":"https://api.github.com/users/superKalo/orgs","repos_url":"https://api.github.com/users/superKalo/repos","events_url":"https://api.github.com/users/superKalo/events{/privacy}","received_events_url":"https://api.github.com/users/superKalo/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-07-04T15:53:01Z","updated_at":"2018-07-30T17:52:51Z","closed_at":null,"author_association":"NONE","body":"I have a seeder that seeds my **States**:\r\n\r\n```javascript\r\nconst states = {\r\n  model: 'State',\r\n  documents: [\r\n    { name: 'Alabama', abbr: 'AL' },\r\n    { name: 'Alaska', abbr: 'AK' },\r\n    { name: 'Arizona', abbr: 'AZ' },\r\n  ],\r\n};\r\n```\r\n\r\nAfter the **States** seeder is done, each document gets _Object ID_ by Mongo.\r\n\r\nThen, I have another seeder, **Survey**. I want to reference the _Object ID_ of one of the states inside it:\r\n\r\n```javascript\r\nconst surveys = {\r\n  model: 'Survey',\r\n  documents: [{\r\n    user: 'superkalo@devlabs.bg',\r\n    state: '<Object ID>' // Object ID of the 'Alabama' document?\r\n  }],\r\n};\r\n```\r\n\r\nAny ideas how to reference any State _Object IDs_ in the Survey seeder?\r\n\r\nI want to reference it somehow dynamic, because each time the **States** seeder executes, documents get different _Object ID_."},"comment":{"url":"https://api.github.com/repos/seanemmer/mongoose-seed/issues/comments/408952573","html_url":"https://github.com/seanemmer/mongoose-seed/issues/28#issuecomment-408952573","issue_url":"https://api.github.com/repos/seanemmer/mongoose-seed/issues/28","id":408952573,"node_id":"MDEyOklzc3VlQ29tbWVudDQwODk1MjU3Mw==","user":{"login":"seanemmer","id":8183188,"node_id":"MDQ6VXNlcjgxODMxODg=","avatar_url":"https://avatars3.githubusercontent.com/u/8183188?v=4","gravatar_id":"","url":"https://api.github.com/users/seanemmer","html_url":"https://github.com/seanemmer","followers_url":"https://api.github.com/users/seanemmer/followers","following_url":"https://api.github.com/users/seanemmer/following{/other_user}","gists_url":"https://api.github.com/users/seanemmer/gists{/gist_id}","starred_url":"https://api.github.com/users/seanemmer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/seanemmer/subscriptions","organizations_url":"https://api.github.com/users/seanemmer/orgs","repos_url":"https://api.github.com/users/seanemmer/repos","events_url":"https://api.github.com/users/seanemmer/events{/privacy}","received_events_url":"https://api.github.com/users/seanemmer/received_events","type":"User","site_admin":false},"created_at":"2018-07-30T17:52:51Z","updated_at":"2018-07-30T17:52:51Z","author_association":"OWNER","body":"Would this solution work:\r\n\r\nHave the populateModels return a promise that resolves with an array of the models that are created.\r\n\r\nYou can then chain populateModels calls and pass the results of a previous populateModels call to a subsequent one."}}
{"actor":{"display_login":"seanemmer"}}