0
remove
操作を、pre.save
フック内のModelB
にModelA
からトリガーしたいとします。モンゴースを使用して異なるモデルのフック内でモデル操作を実行
基本的には任意のModelA
が更新された時は、私はModelB
コレクションをドロップする必要があります。
これは私が試したものです、私はエラーを取得しないが、操作は決して終わらない:
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const ObjectId = Schema.Types.ObjectId;
const permissionSetSchema = require('./permission-set');
const PermissionSet = mongoose.model('PermissionSet', permissionSetSchema);
const roleSchema = new Schema({
name : { type: String, required: true, unique: true, maxLength: 140 },
description: { type: String, maxLength: 300 },
});
roleSchema.post('update', (next, done) => {
PermissionSet.remove({}, err => {
if (err) { next(err); }
next();
});
});
ああ愚かな間違い、ありがとう! – ianaya89