我正在尝试制作一个 CreatedBy Mongoose 插件,但是当尝试使用ObjectId
它给我的字段类型时("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
值以使其工作?