2017-06-28 5 views
0

タイプのデフォルト画像を設定するには、「サムネイル」とURL「https://blalblabla」を設定しますか? mongoose-schemeで作れますか?詳細は?タイプの既定のイメージを設定する方法: 'サムネイル'とURL: 'https:// blalblabla'?

const Images = new Schema({ 
kind: { 
     type: String, 
     enum: ['thumbnail', 'detail'], 
     required: false 
    }, 
    url: { 
     type: String 
    }, 
}); 

const Tags = new Schema({ 
    label: { 
     type: String 
    }, 
}); 

const ArticleScheme = new Schema({ 
    images: [Images], 
    title: {type: String, required: true}, 
    author: {type: String, required: true}, 
    text: {type: String, required: true}, 
    views: { 
     type: Number, 
     default: 123 
    }, 
    tags: [Tags], 
    createdAt: { 
     type: Date 
    } 
}); 
+0

こんにちは、こんにちは、スタックオーバーフローを歓迎します。あなたのここでのやり方を知るために(また、最初のバッジを獲得するために)[welcome tour](https://stackoverflow.com/tour) [Minimal、Complete、Verifiableの例](https://stackoverflow.com/help/mcve)の作成方法と[よくある質問を表示する方法](https://stackoverflow.com/help/how-to)もチェックしてください。あなたがあなたのチャンスを増やし、フィードバックと有用な答えを得ることができます。 – DarkCygnus

答えて

0

あなたはちょうどあなたがこのケースでrequired: falseを必要としないプロパティのデフォルト

kind: { 
    type: String, 
    enum: ['thumbnail', 'detail'], 
    default: 'thumbnail' 
} 

を追加します。

関連する問題