Sau*_*abh 4 mongoose mongodb node.js
我正在创建一个 mongoose 预保存钩子,我想知道模型/集合的名称,我将其保存在预保存钩子中。我可以从哪个变量中得到它。
module.exports = exports = function lastModifiedPlugin (schema, options) {
schema.pre('save', function (next) {
var self = this;
self.constructor.findOne({ _id: self._id }, function (err, launch){
console.log(" model " + self.mongooseCollection);
console.log(Object.getOwnPropertyNames(this));
console.log(Object.getOwnPropertyNames(schema));
next()
});
})
if (options && options.index) {
schema.path('lastMod').index(options.index)
}
}
Run Code Online (Sandbox Code Playgroud)
我试图探索this
和schema
变量的函数和属性,但无法保存名称 od 模型。