{"action":"created","issue":{"url":"https://api.github.com/repos/DefinitelyTyped/DefinitelyTyped/issues/11291","repository_url":"https://api.github.com/repos/DefinitelyTyped/DefinitelyTyped","labels_url":"https://api.github.com/repos/DefinitelyTyped/DefinitelyTyped/issues/11291/labels{/name}","comments_url":"https://api.github.com/repos/DefinitelyTyped/DefinitelyTyped/issues/11291/comments","events_url":"https://api.github.com/repos/DefinitelyTyped/DefinitelyTyped/issues/11291/events","html_url":"https://github.com/DefinitelyTyped/DefinitelyTyped/issues/11291","id":177543402,"number":11291,"title":"Problem defining interfaces for subdocuments with mongoose","user":{"login":"camilleblanc","id":19329550,"avatar_url":"https://avatars.githubusercontent.com/u/19329550?v=3","gravatar_id":"","url":"https://api.github.com/users/camilleblanc","html_url":"https://github.com/camilleblanc","followers_url":"https://api.github.com/users/camilleblanc/followers","following_url":"https://api.github.com/users/camilleblanc/following{/other_user}","gists_url":"https://api.github.com/users/camilleblanc/gists{/gist_id}","starred_url":"https://api.github.com/users/camilleblanc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/camilleblanc/subscriptions","organizations_url":"https://api.github.com/users/camilleblanc/orgs","repos_url":"https://api.github.com/users/camilleblanc/repos","events_url":"https://api.github.com/users/camilleblanc/events{/privacy}","received_events_url":"https://api.github.com/users/camilleblanc/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":32,"created_at":"2016-09-17T00:05:44Z","updated_at":"2016-10-10T17:29:36Z","closed_at":"2016-09-21T04:08:59Z","body":"@simonxca \r\nFollowing our discussion on thread #10110 \r\n\r\nI have another problem with how to declare sub documents.\r\nI have this kind of code:\r\n\r\n```\r\nexport interface MySubEntity {\r\n\tproperty: string;\r\n\tproperty2: string;\r\n}\r\n\r\nexport interface MyEntity extends mongoose.Document {\r\n\tname: string;\r\n\tsub: MySubEntity[];\r\n}\r\n\r\nvar mySubEntitySchema = new Schema({\r\n  property1: String,\r\n  property2: String\r\n});\r\n\r\nvar myEntitySchema = new Schema({\r\n  name: String,\r\n  sub: [mySubEntitySchema]\r\n});\r\n\r\nexport var MyEntityModel: mongoose.Model<MyEntityDocument> = mongoose.model<MyEntityDocument>(\"MyEntity\", myEntitySchema);\r\n```\r\n\r\nNow somewhere I have the _id of a MySubEntity, and I have retrieved the MyEntity where it is. \r\nSo to retrieve my sub entity, I'm filtering on the sub array with the _id:\r\n\r\n`var mySubSearched = _.find(myEntity.sub, function (sub) { return sub._id == mySubId });`\r\n\r\nThe problem is: _id is not a property of the interface MySubEntity, but it has one because mongo creates an _id for subdocuments.\r\n\r\nSo my question is: what is the correct way to declare sub documents?\r\nMy first thought was obviously to make the interface MySubEntity to extend mongoose.Document, but then I have another problem somewhere else: when I want to declare in my code a new MySubEntity... well it asks for all the properties of mongoose.Document that are usually created by mongo!\r\n\r\nI hope my post is clear enough to understand!\r\nThanks in advance if you can enlighten me here, I'm really confused now."},"comment":{"url":"https://api.github.com/repos/DefinitelyTyped/DefinitelyTyped/issues/comments/252686534","html_url":"https://github.com/DefinitelyTyped/DefinitelyTyped/issues/11291#issuecomment-252686534","issue_url":"https://api.github.com/repos/DefinitelyTyped/DefinitelyTyped/issues/11291","id":252686534,"user":{"login":"camilleblanc","id":19329550,"avatar_url":"https://avatars.githubusercontent.com/u/19329550?v=3","gravatar_id":"","url":"https://api.github.com/users/camilleblanc","html_url":"https://github.com/camilleblanc","followers_url":"https://api.github.com/users/camilleblanc/followers","following_url":"https://api.github.com/users/camilleblanc/following{/other_user}","gists_url":"https://api.github.com/users/camilleblanc/gists{/gist_id}","starred_url":"https://api.github.com/users/camilleblanc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/camilleblanc/subscriptions","organizations_url":"https://api.github.com/users/camilleblanc/orgs","repos_url":"https://api.github.com/users/camilleblanc/repos","events_url":"https://api.github.com/users/camilleblanc/events{/privacy}","received_events_url":"https://api.github.com/users/camilleblanc/received_events","type":"User","site_admin":false},"created_at":"2016-10-10T17:29:36Z","updated_at":"2016-10-10T17:29:36Z","body":"@simonxca It works and causes no other issues.\r\nGood job :)"}}
{"actor":{"display_login":"camilleblanc"}}