Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

比如
var PersonSchame = new mongoose.Schema({

name: String,
books: [{
    type:String
}]

});

这时候怎么给books添加数据

有点基础的问题 :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
314 views
Welcome To Ask or Share your Answers For Others

1 Answer

你的意思是往数据库中一条数据的 books字段添加元素吗?如果是的话,参考下面这个例子:

db.personModel.update({
    _id: xxx    //查询到特定的一条数据
}, {
    $push:{
        members: username
    }
}, (err) => {
    //update操作完之后的回调函数
});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...