{"action":"created","issue":{"url":"https://api.github.com/repos/Automattic/mongoose/issues/4308","repository_url":"https://api.github.com/repos/Automattic/mongoose","labels_url":"https://api.github.com/repos/Automattic/mongoose/issues/4308/labels{/name}","comments_url":"https://api.github.com/repos/Automattic/mongoose/issues/4308/comments","events_url":"https://api.github.com/repos/Automattic/mongoose/issues/4308/events","html_url":"https://github.com/Automattic/mongoose/issues/4308","id":164455334,"number":4308,"title":"Why do array sub documents get `_id` by default and object sub documents don't?","user":{"login":"adambuczynski","id":490562,"avatar_url":"https://avatars.githubusercontent.com/u/490562?v=3","gravatar_id":"","url":"https://api.github.com/users/adambuczynski","html_url":"https://github.com/adambuczynski","followers_url":"https://api.github.com/users/adambuczynski/followers","following_url":"https://api.github.com/users/adambuczynski/following{/other_user}","gists_url":"https://api.github.com/users/adambuczynski/gists{/gist_id}","starred_url":"https://api.github.com/users/adambuczynski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adambuczynski/subscriptions","organizations_url":"https://api.github.com/users/adambuczynski/orgs","repos_url":"https://api.github.com/users/adambuczynski/repos","events_url":"https://api.github.com/users/adambuczynski/events{/privacy}","received_events_url":"https://api.github.com/users/adambuczynski/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-07-08T04:05:42Z","updated_at":"2016-07-10T20:54:16Z","closed_at":"2016-07-10T20:45:09Z","body":"Say I have a product schema with a nested color sub document which references a color and implements denormalization for the name:\r\n\r\n```js\r\nlet ProductSchema = new Schema({\r\n  name: String,\r\n  color: {\r\n    id: {\r\n      type: Schema.Types.ObjectId,\r\n      ref: 'Color',\r\n    },\r\n    name: String,\r\n  },\r\n};\r\n```\r\n\r\nThis does not automatically get an `_id` field and works as expected.\r\n\r\nHowever, when I create an array of sub documents, e.g.:\r\n\r\n```js\r\nlet SuggestionSchema = new Schema({\r\n  name: String,\r\n  products: [{\r\n    id: {\r\n      type: Schema.Types.ObjectId,\r\n      ref: 'Product',\r\n    },\r\n    name: String,\r\n    color: {\r\n      id: {\r\n        type: Schema.Types.ObjectId,\r\n        ref: 'Color',\r\n      },\r\n      name: String,\r\n    },\r\n  }],\r\n});\r\n```\r\n\r\nThese *do* get `_id`'s automatically appended. Why this discrepancy, is there a reason behind it?\r\n\r\nI know I can disable it by defining a sub schema and specifying `_id: false`, but I don't understand why it's false by default when nesting just a single document, but not when nesting an array of sub documents. Isn't the most common use case to *not* need the `_id`'s?"},"comment":{"url":"https://api.github.com/repos/Automattic/mongoose/issues/comments/231610311","html_url":"https://github.com/Automattic/mongoose/issues/4308#issuecomment-231610311","issue_url":"https://api.github.com/repos/Automattic/mongoose/issues/4308","id":231610311,"user":{"login":"adambuczynski","id":490562,"avatar_url":"https://avatars.githubusercontent.com/u/490562?v=3","gravatar_id":"","url":"https://api.github.com/users/adambuczynski","html_url":"https://github.com/adambuczynski","followers_url":"https://api.github.com/users/adambuczynski/followers","following_url":"https://api.github.com/users/adambuczynski/following{/other_user}","gists_url":"https://api.github.com/users/adambuczynski/gists{/gist_id}","starred_url":"https://api.github.com/users/adambuczynski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adambuczynski/subscriptions","organizations_url":"https://api.github.com/users/adambuczynski/orgs","repos_url":"https://api.github.com/users/adambuczynski/repos","events_url":"https://api.github.com/users/adambuczynski/events{/privacy}","received_events_url":"https://api.github.com/users/adambuczynski/received_events","type":"User","site_admin":false},"created_at":"2016-07-10T20:54:16Z","updated_at":"2016-07-10T20:54:16Z","body":"Ok thanks"}}
{"actor":{"display_login":"adambuczynski"}}