MongoDB/Mongoose:MarkModified 嵌套对象 [英] MongoDB / Mongoose: MarkModified a nested object
本文介绍了MongoDB/Mongoose:MarkModified 嵌套对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
不幸的是,我没有可以对此进行测试的记录,但我无法在任何地方找到有关此的任何信息.
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},
}
}
我想更新doc.email.data
.我需要使用 markModified()
否则数据将无法正确保存.
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();
或者我只做 markModified('email')
而 Mongoose 会解决其余的问题?
Or do I just do markModified('email')
and Mongoose will work out the rest?
推荐答案
你需要提供修改对象字段的完整路径,所以应该是:
You need to provide the full path the modified object field, so it should be:
doc.markModified('email.data');
这篇关于MongoDB/Mongoose:MarkModified 嵌套对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文