{"action":"created","issue":{"url":"https://api.github.com/repos/Automattic/mongoose/issues/6520","repository_url":"https://api.github.com/repos/Automattic/mongoose","labels_url":"https://api.github.com/repos/Automattic/mongoose/issues/6520/labels{/name}","comments_url":"https://api.github.com/repos/Automattic/mongoose/issues/6520/comments","events_url":"https://api.github.com/repos/Automattic/mongoose/issues/6520/events","html_url":"https://github.com/Automattic/mongoose/issues/6520","id":326491968,"number":6520,"title":"Populating across Databases using Dynamic References","user":{"login":"mushfau","id":14769830,"avatar_url":"https://avatars0.githubusercontent.com/u/14769830?v=4","gravatar_id":"","url":"https://api.github.com/users/mushfau","html_url":"https://github.com/mushfau","followers_url":"https://api.github.com/users/mushfau/followers","following_url":"https://api.github.com/users/mushfau/following{/other_user}","gists_url":"https://api.github.com/users/mushfau/gists{/gist_id}","starred_url":"https://api.github.com/users/mushfau/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mushfau/subscriptions","organizations_url":"https://api.github.com/users/mushfau/orgs","repos_url":"https://api.github.com/users/mushfau/repos","events_url":"https://api.github.com/users/mushfau/events{/privacy}","received_events_url":"https://api.github.com/users/mushfau/received_events","type":"User","site_admin":false},"labels":[{"id":29038163,"url":"https://api.github.com/repos/Automattic/mongoose/labels/enhancement","name":"enhancement","color":"02d7e1","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/Automattic/mongoose/milestones/204","html_url":"https://github.com/Automattic/mongoose/milestone/204","labels_url":"https://api.github.com/repos/Automattic/mongoose/milestones/204/labels","id":3046764,"number":204,"title":"5.2","description":"","creator":{"login":"vkarpov15","id":1620265,"avatar_url":"https://avatars2.githubusercontent.com/u/1620265?v=4","gravatar_id":"","url":"https://api.github.com/users/vkarpov15","html_url":"https://github.com/vkarpov15","followers_url":"https://api.github.com/users/vkarpov15/followers","following_url":"https://api.github.com/users/vkarpov15/following{/other_user}","gists_url":"https://api.github.com/users/vkarpov15/gists{/gist_id}","starred_url":"https://api.github.com/users/vkarpov15/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vkarpov15/subscriptions","organizations_url":"https://api.github.com/users/vkarpov15/orgs","repos_url":"https://api.github.com/users/vkarpov15/repos","events_url":"https://api.github.com/users/vkarpov15/events{/privacy}","received_events_url":"https://api.github.com/users/vkarpov15/received_events","type":"User","site_admin":false},"open_issues":13,"closed_issues":0,"state":"open","created_at":"2018-01-18T21:19:10Z","updated_at":"2018-05-25T15:03:09Z","due_on":"2018-07-02T07:00:00Z","closed_at":null},"comments":0,"created_at":"2018-05-25T11:50:49Z","updated_at":"2018-05-25T15:06:33Z","closed_at":null,"author_association":"NONE","body":"<!-- *Before creating an issue please make sure you are using the latest version of mongoose -->\r\n[](url)\r\n**Do you want to request a *feature* or report a *bug*\r\n**BUG** or a **FEATURE**\r\n\r\n**What is the current behavior?**\r\nPopulating dynamically referenced cross-database models throws MissingSchemaError\r\n\r\n> MissingSchemaError: Schema hasn't been registered for model \"Book\". \r\nUse mongoose.model(name, schema)\r\n\r\nit works as needed if the referenced models are in the same database\r\n\r\n\r\n**If the current behavior is a bug, please provide the steps to reproduce.**\r\n<!-- If you can, provide a standalone script / gist to reproduce your issue -->\r\nthe behavior is reproduced in the gist available [here](https://gist.github.com/mushfau/06a36e243c2831183f3bda1b94843731)\r\n\r\n\r\n**What is the expected behavior?**\r\npopulate the the dynamically referenced models even though they are in across databases \r\n\r\n\r\n**Please mention your node.js, mongoose and MongoDB version.**\r\nMongoDB version: 3.4.3\r\nMongoose version: 5.1.2\r\nNodeJS version: 8.11.1\r\n"},"comment":{"url":"https://api.github.com/repos/Automattic/mongoose/issues/comments/392087532","html_url":"https://github.com/Automattic/mongoose/issues/6520#issuecomment-392087532","issue_url":"https://api.github.com/repos/Automattic/mongoose/issues/6520","id":392087532,"user":{"login":"vkarpov15","id":1620265,"avatar_url":"https://avatars2.githubusercontent.com/u/1620265?v=4","gravatar_id":"","url":"https://api.github.com/users/vkarpov15","html_url":"https://github.com/vkarpov15","followers_url":"https://api.github.com/users/vkarpov15/followers","following_url":"https://api.github.com/users/vkarpov15/following{/other_user}","gists_url":"https://api.github.com/users/vkarpov15/gists{/gist_id}","starred_url":"https://api.github.com/users/vkarpov15/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vkarpov15/subscriptions","organizations_url":"https://api.github.com/users/vkarpov15/orgs","repos_url":"https://api.github.com/users/vkarpov15/repos","events_url":"https://api.github.com/users/vkarpov15/events{/privacy}","received_events_url":"https://api.github.com/users/vkarpov15/received_events","type":"User","site_admin":false},"created_at":"2018-05-25T15:06:33Z","updated_at":"2018-05-25T15:06:33Z","author_association":"COLLABORATOR","body":"We currently don't support this. [Cross-db populate](http://mongoosejs.com/docs/populate.html#cross-db-populate) only works if you pass in the whole mongoose model object to `populate()`. You can't store mongoose models in mongodb, so dynref relies fully on model names, and when you pass a model name to `populate()` mongoose only looks in the current connection for models with that name.\r\n\r\nWe'll add support for this, shouldn't be too hard. I think the idea will be to add a `connection` option to `populate()` that lets you specify the [connection](http://mongoosejs.com/docs/connections.html) to use for looking up model names.  The code would look like this:\r\n\r\n```javascript\r\n// Tell mongoose to look in `hobby_db` for models named 'Movie' and 'User'\r\nawait User.find({}).populate({ path: 'hobby', connection: hobby_db });\r\n```"}}
{"actor":{"display_login":"vkarpov15"}}