这是我的代码的相关片段
MySchema
.pre('save', function (next) {
var self = this;
console.log(self);
return next();
});
MySchema
.post('save', function (next) {
var self = this;
console.log(self);
});
出于某种原因,在这种情况下,预保存挂钩会提供适当的对象
{ farm: 557ce790a893e4e0118059e3,
_id: 557ce791a893e4e011805a35,
privileges:
[ { instanceId: 557ce790a893e4e0118059bb,
access: 5,
modelType: 'User' } ],
public: 0,
properties: { crop: 'No Crop', name: 'Pirani Tract 50' },
geometry: { type: 'Polygon', coordinates: [ [Object] ] } }
但是帖子保存挂钩只是记录
{ domain: null,
_events:
{ save: [ [Function: notify], [Function] ],
isNew: [Function: notify],
init: [Function] },
_maxListeners: 0 }
答案 0 :(得分:1)
post
中间件接收文档作为参数,而不是next
中间件接收的pre
流控制回调参数。
MySchema
.post('save', function(doc) {
console.log(doc);
});