最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - MongoDBMongoose: MarkModified a nested object - Stack Overflow

programmeradmin1浏览0评论

Unfortunately I don't have a record I can test this on, but I can't find any information on this anywhere.

Say I have a document like this:

{
  email:  {
       type: 'Gmail',
       data: {//freeform data},
    }
}

I want to update doc.email.data. I need to use markModified() or else the data won't save correctly.

Do I mark modified like this?

doc.email.data = newData;
doc.markModified('email.data');
doc.save();

Or do I just do markModified('email') and Mongoose will work out the rest?

Unfortunately I don't have a record I can test this on, but I can't find any information on this anywhere.

Say I have a document like this:

{
  email:  {
       type: 'Gmail',
       data: {//freeform data},
    }
}

I want to update doc.email.data. I need to use markModified() or else the data won't save correctly.

Do I mark modified like this?

doc.email.data = newData;
doc.markModified('email.data');
doc.save();

Or do I just do markModified('email') and Mongoose will work out the rest?

Share Improve this question asked Jan 14, 2016 at 3:02 JVGJVG 21.2k48 gold badges140 silver badges215 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 18

You need to provide the full path the modified object field, so it should be:

doc.markModified('email.data');
发布评论

评论列表(0)

  1. 暂无评论