{"action":"created","issue":{"url":"https://api.github.com/repos/Automattic/mongoose/issues/3105","labels_url":"https://api.github.com/repos/Automattic/mongoose/issues/3105/labels{/name}","comments_url":"https://api.github.com/repos/Automattic/mongoose/issues/3105/comments","events_url":"https://api.github.com/repos/Automattic/mongoose/issues/3105/events","html_url":"https://github.com/Automattic/mongoose/issues/3105","id":91150232,"number":3105,"title":"MissingSchemaError: Schema hasn't been registered for model","user":{"login":"abr4xas","id":405484,"avatar_url":"https://avatars.githubusercontent.com/u/405484?v=3","gravatar_id":"","url":"https://api.github.com/users/abr4xas","html_url":"https://github.com/abr4xas","followers_url":"https://api.github.com/users/abr4xas/followers","following_url":"https://api.github.com/users/abr4xas/following{/other_user}","gists_url":"https://api.github.com/users/abr4xas/gists{/gist_id}","starred_url":"https://api.github.com/users/abr4xas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abr4xas/subscriptions","organizations_url":"https://api.github.com/users/abr4xas/orgs","repos_url":"https://api.github.com/users/abr4xas/repos","events_url":"https://api.github.com/users/abr4xas/events{/privacy}","received_events_url":"https://api.github.com/users/abr4xas/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-06-26T04:35:22Z","updated_at":"2015-06-26T13:34:35Z","closed_at":null,"body":"Error:\r\n\r\n```js\r\n/var/www/html/noodetest/node_modules/mongoose/lib/index.js:329\r\n      throw new mongoose.Error.MissingSchemaError(name);\r\n            ^\r\nMissingSchemaError: Schema hasn't been registered for model \"User\".\r\nUse mongoose.model(name, schema)\r\n    at Mongoose.model (/var/www/html/noodetest/node_modules/mongoose/lib/index.js:329:13)\r\n    at Object.<anonymous> (/var/www/html/noodetest/app/models/rrss.js:3:29)\r\n    at Module._compile (module.js:460:26)\r\n    at Object.Module._extensions..js (module.js:478:10)\r\n    at Module.load (module.js:355:32)\r\n    at Function.Module._load (module.js:310:12)\r\n    at Module.require (module.js:365:17)\r\n    at require (module.js:384:17)\r\n    at Object.<anonymous> (/var/www/html/noodetest/server.js:36:14)\r\n    at Module._compile (module.js:460:26)\r\n    at Object.Module._extensions..js (module.js:478:10)\r\n    at Module.load (module.js:355:32)\r\n    at Function.Module._load (module.js:310:12)\r\n    at Function.Module.runMain (module.js:501:10)\r\n    at startup (node.js:129:16)\r\n    at node.js:814:3\r\n```\r\n\r\nModel user:\r\n\r\n```js\r\nvar mongoose     = require('mongoose'),\r\n    Schema       = mongoose.Schema,\r\n    Social       = mongoose.model('Social');\r\n\r\nvar userSchema   = new mongoose.Schema({\r\n    name: { type:  Schema.Types.String, required: true },\r\n    nick: { type:  Schema.Types.String, required: true },\r\n    bio: { type:  Schema.Types.String, required: true },\r\n    avatar: { type:  Schema.Types.String, required: false },\r\n    rrss: [\r\n        {\r\n            type: Schema.Types.ObjectId, ref: 'Social'\r\n        }\r\n    ]\r\n});\r\n\r\nmodule.exports = mongoose.model('User', userSchema);\r\n```\r\n\r\nModel social:\r\n\r\n```js\r\nvar mongoose     = require('mongoose'),\r\n    Schema       = mongoose.Schema,\r\n    User         = mongoose.model('User');\r\n\r\nvar socialSchema   = new mongoose.Schema({\r\n    twitter: { type:  Schema.Types.String },\r\n    github: { type:  Schema.Types.String },\r\n    web: { type:  Schema.Types.String },\r\n    user_id: [\r\n        {\r\n            type: Schema.Types.String, ref: 'User'\r\n        }\r\n    ]\r\n});\r\n\r\nmodule.exports = mongoose.model('Social', socialSchema);\r\n```\r\n\r\n```js\r\n// Load models\r\nvar Social = require('./app/models/rrss'),\r\n    User   = require('./app/models/user'),\r\n    Schema = mongoose.Schema;\r\n```\r\n\r\nWhat i miss?"},"comment":{"url":"https://api.github.com/repos/Automattic/mongoose/issues/comments/115689998","html_url":"https://github.com/Automattic/mongoose/issues/3105#issuecomment-115689998","issue_url":"https://api.github.com/repos/Automattic/mongoose/issues/3105","id":115689998,"user":{"login":"vkarpov15","id":1620265,"avatar_url":"https://avatars.githubusercontent.com/u/1620265?v=3","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":"2015-06-26T13:34:35Z","updated_at":"2015-06-26T13:34:35Z","body":"You called `require()` on the social schema first, which attempts to compile the 'Social' model that references a 'User' model that isn't defined until later. Since you have circular refs, there's no way for mongoose to successfully compile these models, which is fine since circular refs are often indicative of poor schema design choices."}}