2016-09-04 24 views
0

レコードをコレクションに追加するときに、配列オブジェクトをデフォルト値としてサブ配列に追加します。以下は私がこのコレクションにレコードを作成するときにASSIGNEE_WORKERS配列にデフォルトの配列を追加したい見ることができます私のchemaレコードをコレクションに追加するときに、Mongooseがデフォルトの配列オブジェクトをサブ配列に追加します。

const JobSpecificetionSchema = new Schema({ 
ACTIVITY:[{ 
    DESCRIPTION: { type: String, default: '' }, 
    SUB_ACTIVITY:[{ 
     DESCRIPTION: { type: String, default: '' }, 
     REPEAT_TYPE: { type: String, default: '' },// 1 - inspection will start 2 - inspection will not start 
     FREQUENCY: { type: String, default: '' }, // 1 - weekly, 2 - monthly, 3 - yearly 
     PAR_1: { type: String, default: '' }, // if weekly, then every one week or two. then monthly every one month or two months 
     PAR_2: { type: String, default: '' }, // if weekly then days in the week. ie (Monday 1, tue 2) (1,2,3) Monthly- day ie 25 yearly- month ie 1 to 12 
     PAR_3: { type: String, default: '' }, // if yearly then day 25 
     ASSIGNEE_WORKERS:[{ 
     ASSIGNEE_ID : { type: Schema.Types.ObjectId, default: '000000000000000000000000' }, 
     }] 
    }] 
    }] 

}); 

を見つけてください。

現在の方法は機能しません。このために助けてください

答えて

0

"pre save"フックを使用して、新しい文書(文書上のisNewプロパティ、文書自体がプリセーブフック内で "this"としてアクセス可能)を割り当てることができます)それがあなたの望むものならば。

+0

私にいくつかの例を教えてください –

関連する問題