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)

 

posted @ 2020-06-08 10:32  山吹同学  阅读(618)  评论(0编辑  收藏  举报