如何在mongoose中使用自定义types?

我有以下架构:

var Location = new Schema({ x: { type: String }, y: { type: String } },{ _id: false }); var AppSchema = new Schema({ link: { type: String }, location: { type: Location } }) 

上述不工作,我收到以下错误:

'location'处未定义的types

Mongoose中有特定的有效types,在这里find: http : //mongoosejs.com/docs/schematypes.html

如果我是你,我会考虑使用type: Schema.Types.Mixedtypes。 引用mongoose文档,这实际上是一种“任何事情”的types。