关于ZAKER 融媒体解决方案 合作 加入

node.js- 编写 Mongoose Plug In- plugin ( ) 方法?

CocoaChina 11-13

我有兴趣编写一个猫鼬插件来填写所有必填字段 . 我知道还有其他方法可以执行此操作 , 但是我喜欢编写自己的插件的想法 .

从文档http://mongoosejs.com/docs/plugins开始:

// game-schema.jsvar lastMod = require ( './lastMod' ) ;var Game = new Schema ( { ... } ) ;Game.plugin ( lastMod, { index: true } ) ;

但是当我从架构中创建模型并查看属性时 , 没有看到 plugin ( ) 方法:

var mongoose = require ( 'mongoose' ) ;var CpuSchema = require ( "../schemas/cpu" ) ;var Cpu = mongoose.model ( 'Cpu', CpuSchema ) ;console.log ( Cpu ) ;module.exports = Cpu;

one@demo ~/cloudimageshare-monitoring/project $node /home/one/cloudimageshare-monitoring/project/app/data/models/cpu.js { [ Function: model ] base: { connections: [ [ Object ] ] , plugins: [ ] , models: { Cpu: [ Circular ] }, modelSchemas: { Cpu: [ Object ] }, options: { pluralization: true } }, modelName: 'Cpu', model: [ Function: model ] , db: { base: { connections: [ Object ] , plugins: [ ] , models: [ Object ] , modelSchemas: [ Object ] , options: [ Object ] }, collections: { cpus: [ Object ] }, models: {}, replica: false, hosts: null, host: null, port: null, user: null, pass: null, name: null, options: null, otherDbs: [ ] , _readyState: 0, _closeCalled: false, _hasOpened: false, _listening: false }, discriminators: undefined, schema: { paths: { timeStamp: [ Object ] , avaiable: [ Object ] , status: [ Object ] , metrics: [ Object ] , _id: [ Object ] , __v: [ Object ] }, subpaths: {}, virtuals: { id: [ Object ] }, nested: {}, inherits: {}, callQueue: [ ] , _indexes: [ ] , methods: {}, statics: {}, tree: { timeStamp: [ Object ] , avaiable: [ Function: Boolean ] , status: [ Function: String ] , metrics: [ Object ] , _id: [ Object ] , id: [ Object ] , __v: [ Function: Number ] }, _requiredpaths: undefined, discriminatorMapping: undefined, _indexedpaths: undefined, options: { id: true, noVirtualId: false, _id: true, noId: false, read: null, shardKey: null, autoIndex: true, minimize: true, discriminatorKey: '__t', versionKey: '__v', capped: false, bufferCommands: true, strict: true, pluralization: true }, _events: {} }, options: undefined, collection: { collection: null, opts: { bufferCommands: true, capped: false }, name: 'cpus', conn: { base: [ Object ] , collections: [ Object ] , models: {}, replica: false, hosts: null, host: null, port: null, user: null, pass: null, name: null, options: null, otherDbs: [ ] , _readyState: 0, _closeCalled: false, _hasOpened: false, _listening: false }, queue: [ [ Object ] ] , buffer: true } }

在模型上 , 我没有看到 plugin ( ) 方法 .

以上内容由"CocoaChina"上传发布 查看原文
相关标签 方法app