{"action":"opened","issue":{"url":"https://api.github.com/repos/ga-wdi-boston/group-project/issues/108","repository_url":"https://api.github.com/repos/ga-wdi-boston/group-project","labels_url":"https://api.github.com/repos/ga-wdi-boston/group-project/issues/108/labels{/name}","comments_url":"https://api.github.com/repos/ga-wdi-boston/group-project/issues/108/comments","events_url":"https://api.github.com/repos/ga-wdi-boston/group-project/issues/108/events","html_url":"https://github.com/ga-wdi-boston/group-project/issues/108","id":154808723,"number":108,"title":"Pushing subdoc to parent, error on push","user":{"login":"susandaiute","id":16547482,"avatar_url":"https://avatars.githubusercontent.com/u/16547482?v=3","gravatar_id":"","url":"https://api.github.com/users/susandaiute","html_url":"https://github.com/susandaiute","followers_url":"https://api.github.com/users/susandaiute/followers","following_url":"https://api.github.com/users/susandaiute/following{/other_user}","gists_url":"https://api.github.com/users/susandaiute/gists{/gist_id}","starred_url":"https://api.github.com/users/susandaiute/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/susandaiute/subscriptions","organizations_url":"https://api.github.com/users/susandaiute/orgs","repos_url":"https://api.github.com/users/susandaiute/repos","events_url":"https://api.github.com/users/susandaiute/events{/privacy}","received_events_url":"https://api.github.com/users/susandaiute/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-05-13T22:00:54Z","updated_at":"2016-05-13T22:00:54Z","closed_at":null,"body":"We have users that have many locations. Locations are subdocs in user.  We're trying to push a new location to a user and we're getting the error\r\n```{\"error\":{\"message\":\"this._schema.caster.cast is not a function\",\"error\":{}}}```\r\n\r\ncontroller\r\n```\r\nconst controller = require('lib/wiring/controller');\r\nconst models = require('app/models');\r\nconst User = models.user;\r\nconst Location = models.location;\r\n\r\n\r\nconst create = (req, res, next) => {\r\n  User.findById(req.body.user.id).then (function(user){\r\n    let location = Object.assign(req.body.location);\r\n    user.locations.push(location);\r\n    return user.save();\r\n  })\r\n  .then(user => res.json({ user }))\r\n  .catch(err => next(err));\r\n};\r\n```\r\nConsole logging location, user.location, and user returns what we expect it to, the problem seems to be in push().\r\n\r\nUser model\r\n```\r\nconst locationSchema = require('./location.js');\r\n\r\nconst userSchema = new mongoose.Schema({\r\n  email: {\r\n    type: String,\r\n    unique: true,\r\n    required: true,\r\n  },\r\n  token: {\r\n    type: String,\r\n    require: true,\r\n  },\r\n  locations:  [locationSchema],\r\n  passwordDigest: String,\r\n}, {\r\n  timestamps: true,\r\n});\r\n```\r\n\r\nLocation Model\r\n\r\n```\r\nconst mongoose = require('mongoose');\r\n\r\nconst locationSchema = new mongoose.Schema({\r\n  name: {\r\n    type: String,\r\n    required: true\r\n  },\r\n  city: {\r\n    type: String,\r\n  },\r\n  region: {\r\n    type: String,\r\n  },\r\n  country: {\r\n    type: String,\r\n  },\r\n  coords: {\r\n    lat: {\r\n      type: Number,\r\n      require: true\r\n    },\r\n    long: {\r\n      type: Number,\r\n      require: true\r\n    },\r\n  },\r\n  visited: {\r\n    type: Boolean,\r\n    require: true,\r\n    default: false,\r\n  },\r\n  comment: {\r\n    type: String,\r\n  },\r\n}, {\r\n  timestamps: true,\r\n});\r\n\r\n\r\nconst Location = mongoose.model('Location', locationSchema);\r\n\r\nmodule.exports = Location;\r\n```\r\n\r\n"}}