mongoose中给所有记录添加新属性

参考:https://mongoosejs.com/docs/api.html#schema_Schema-add 详情请查看这个网址

const mongoose=require("./dbConn.js")
const Schema=mongoose.Schema;

// 这是添加的属性
const addSchema=new Schema()
addSchema.add({articleTitle:String,articleImg:String})
// 这是添加的属性


let loveSchema=new Schema({
    userId:{
        type:String
    },
    articleId:{
        type:String
    },
    isLove:{
        type:Boolean,
        default:false
    },
    love_time:{
        type:Date,
        default:Date.now()
    }
})
loveSchema.add(addSchema)
module.exports=mongoose.model("love",loveSchema)
原文地址:https://www.cnblogs.com/shanchui/p/13064182.html