【发布时间】:2022-01-07 04:37:56
【问题描述】:
如何创建具有默认值的对象数组?
const schema = new mongoose.Schema({
login: {type: String, unique: true, required: true},
password: {type: String, required: true},
chatlist: [
{
channelname: {type: String, default: "frontend"},
channelid: {type: String, default: "619a6bfe5b0931f1e5dbaf2c"}
},
{
channelname: {type: String, default: "backend"},
channelid: {type: String, default: "619a71002954ba23a951bb8f"}
},
{
channelname: {type: String, default: "devops"},
channelid: {type: String, default: "619d69c190a85a40893b6522"}
},
]
})
上面的代码不起作用
当新用户注册时,我想在他的个人资料中添加默认聊天
接下来是用户必须能够从数据库中添加/删除聊天
我该怎么做?聊天需要是对象还是文档?
【问题讨论】:
标签: mongodb mongoose mongoose-schema