簡體   English   中英

在架構默認情況下使用自定義功能?

[英]Use custom function in default of schema?

我有一個這樣的架構:

   new mongoose.Schema({
     name: String,
     uniq: {type: String, default: Math.random() + "a"},
   })

我不能隨機,但對於uniq字段只能為null

默認情況下可以使用自定義功能嗎?

采用

uniq: {type: String, default: function(){ return Math.random() + "a"; } }

檢查貓鼬文件

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM