mongodb - How mongoose adds data to array documents
phpcn_u1582
phpcn_u1582 2017-05-02 09:24:46
0
2
794

For example
var PersonSchame = new mongoose.Schema({

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

});

How to add data to books at this time

Basic question :)

phpcn_u1582
phpcn_u1582

reply all(2)
左手右手慢动作

Do you mean to add elements to the books field of a piece of data in the database? If so, refer to the following example:

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

See the old post, which contains the $push part of Mongoose:

/q/10...

For reference.

Love MongoDB! Have Fun!

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template