{"action":"created","issue":{"url":"https://api.github.com/repos/Automattic/mongoose/issues/2814","labels_url":"https://api.github.com/repos/Automattic/mongoose/issues/2814/labels{/name}","comments_url":"https://api.github.com/repos/Automattic/mongoose/issues/2814/comments","events_url":"https://api.github.com/repos/Automattic/mongoose/issues/2814/events","html_url":"https://github.com/Automattic/mongoose/issues/2814","id":65269323,"number":2814,"title":"db.collection.ensureIndex doesn't get invoked on complex type","user":{"login":"skotchio","id":1432812,"avatar_url":"https://avatars.githubusercontent.com/u/1432812?v=3","gravatar_id":"","url":"https://api.github.com/users/skotchio","html_url":"https://github.com/skotchio","followers_url":"https://api.github.com/users/skotchio/followers","following_url":"https://api.github.com/users/skotchio/following{/other_user}","gists_url":"https://api.github.com/users/skotchio/gists{/gist_id}","starred_url":"https://api.github.com/users/skotchio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/skotchio/subscriptions","organizations_url":"https://api.github.com/users/skotchio/orgs","repos_url":"https://api.github.com/users/skotchio/repos","events_url":"https://api.github.com/users/skotchio/events{/privacy}","received_events_url":"https://api.github.com/users/skotchio/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Automattic/mongoose/labels/help","name":"help","color":"FFFFFF"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-03-30T18:11:36Z","updated_at":"2015-04-01T07:50:28Z","closed_at":"2015-03-31T20:38:41Z","body":"If I define my `location` field like the following way:\r\n\r\n    var Schema = new mongoose.Schema({});\r\n    Schema.add({\r\n       location: {\r\n           name: {type: String},\r\n           loc: {type: [Number], index: '2d'}\r\n        }\r\n    });\r\n\r\nI get the following correct message `Mongoose: db.collection.ensureIndex({ 'location.loc': '2d' }) { safe: undefined, background: true } ` in my console log.\r\n\r\nBut if I define the same field by the following way:\r\n\r\n    var Schema = new mongoose.Schema({});\r\n    Schema.add({\r\n       location: {\r\n           type: {\r\n               name: {type: String},\r\n               loc: {type: [Number], index: '2d'}\r\n           }\r\n        }\r\n    });\r\n\r\nI don't get the message about ensuring index on `location.loc` field and therefore it does not created if not exist "},"comment":{"url":"https://api.github.com/repos/Automattic/mongoose/issues/comments/88383753","html_url":"https://github.com/Automattic/mongoose/issues/2814#issuecomment-88383753","issue_url":"https://api.github.com/repos/Automattic/mongoose/issues/2814","id":88383753,"user":{"login":"skotchio","id":1432812,"avatar_url":"https://avatars.githubusercontent.com/u/1432812?v=3","gravatar_id":"","url":"https://api.github.com/users/skotchio","html_url":"https://github.com/skotchio","followers_url":"https://api.github.com/users/skotchio/followers","following_url":"https://api.github.com/users/skotchio/following{/other_user}","gists_url":"https://api.github.com/users/skotchio/gists{/gist_id}","starred_url":"https://api.github.com/users/skotchio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/skotchio/subscriptions","organizations_url":"https://api.github.com/users/skotchio/orgs","repos_url":"https://api.github.com/users/skotchio/repos","events_url":"https://api.github.com/users/skotchio/events{/privacy}","received_events_url":"https://api.github.com/users/skotchio/received_events","type":"User","site_admin":false},"created_at":"2015-04-01T07:50:28Z","updated_at":"2015-04-01T07:50:28Z","body":"@vkarpov15 unfortunatelly when I tried the following:\r\n\r\n    var Schema = new mongoose.Schema({});\r\n    Schema.add({\r\n      location: {\r\n        kind: {\r\n           name: {type: String},\r\n           loc: {type: [Number], index: '2d'}\r\n        }\r\n      }\r\n    });\r\n\r\nI get the following error:\r\n\r\n```\r\nc:\\Users\\user\\WebstormProjects\\project\\node_modules\\mongoose\\node_modules\\mongodb\\lib\\utils.js:97\r\n    process.nextTick(function() { throw err; });\r\n                                        ^\r\nTypeError: boolean is not a function\r\n    at new SchemaArray (c:\\Users\\user\\WebstormProjects\\project\\node_modules\\mongoose\\lib\\schema\\array.js:58:19)\r\n    at Function.Schema.interpretAsType (c:\\Users\\user\\WebstormProjects\\project\\node_modules\\mongoose\\lib\\schema.js:427:12)\r\n    at Schema.path (c:\\Users\\user\\WebstormProjects\\project\\node_modules\\mongoose\\lib\\schema.js:378:29)\r\n    at Schema.add (c:\\Users\\user\\WebstormProjects\\project\\node_modules\\mongoose\\lib\\schema.js:288:12)\r\n    at Schema.add (c:\\Users\\user\\WebstormProjects\\project\\node_modules\\mongoose\\lib\\schema.js:283:14)\r\n    at Object.<anonymous> (c:\\Users\\user\\WebstormProjects\\project\\app\\models\\AdStoryModel.js:101:10)\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```"}}