Tag: coffeescript mongoose mongoose

在Mongoose插件中添加字段给出“TypeError:架构pathCreatedBy.type”的无效值

我试图做一个CreatedBy Mongoose插件,但是当试图使用ObjectId作为字段types时,它给了我( "account"是另一个定义的集合已经): TypeError: Invalid value for schema path `CreatedBy.type` 这里是插件代码: mongoose = require 'mongoose' module.exports = exports = updatedByPlugin = (schema, options) -> schema.add CreatedBy: type: mongoose.Schema.Types.ObjectId ref: "account" schema.pre "save", (next) -> @CreatedBy = options.accountId next() return schema.path("CreatedBy").index options.index if options and options.index return 那么如何修改ref值使其工作?