search

Home  >  Q&A  >  body text

mongodb - How mongoose adds data to array documents

For example
var PersonSchame = new mongoose.Schema({

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

});

How to add data to books at this time

Basic question :)

phpcn_u1582phpcn_u15822832 days ago823

reply all(2)I'll reply

  • ringa_lee

    ringa_lee2017-05-02 09:26:46

    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操作完之后的回调函数
    });

    reply
    0
  • 高洛峰

    高洛峰2017-05-02 09:26:46

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

    /q/10...

    For reference.

    Love MongoDB! Have Fun!

    reply
    0
  • Cancelreply