添加到 mongodb 中的嵌套文档数组

问题描述

我正在尝试创建用于向现有用户添加地址的 API 路由

用户架构

 const userSchema = new mongoose.Schema({
        name  : type: String,email : type : String,password: type: String,address : [{type: mongoose.Schema.Types.ObjectId,ref: "Address"}],});
module.exports = mongoose.model('User',userSchema);

地址架构

addressSchema = new mongoose.Schema({
    name  : type: String,phone_number : type : Number,address1: type: String,address2: type: String,landmark: type: String,coordinates: [Number],created_at: { type: Date,default: Date.Now()}
});

module.exports = mongoose.model('Address',addressSchema);

如何向现有用户添加新地址?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)