猫鼬更新嵌入式文档不起作用 [英] Mongoose update embedded document does not work

查看:61
本文介绍了猫鼬更新嵌入式文档不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

打招呼

我定义了一个深度嵌入的猫鼬模型"Person",其中包含一个字段"Contact",并且"Contact"具有用于此人的工作,住所,送货等地址的"Address"数组.

I defined a deeply embedded mongoose model "Person", which contains a field "Contact", and "Contact" has an array of "Address" for this person's work, home, delivery etc addresses.

当我想更新地址并使用模型的保存"功能时,更改未反映在数据库中.

When I wanted to update an address, and use the model's "save" function, the change wasn't reflected in the database.

            console.log(person.Contact.Address[i].City = 'Chicago');
            person.save(function (err) {
                if (!err) {
                   console.log(person.Contact.Address[i].City);

console.log指示字段城市"已更新为新值,但mongodb的值保持不变.

The console.log indicates that the field City has been updated to new value, but the mongodb's value stays the same.

您能帮我解决这个问题吗?

Could you please help me with this issue?

谢谢! 加里

推荐答案

通过使用仍然不确定何时需要使用markModified,因为在大多数其他情况下,更改未反映在mongodb中.

Still not sure when I need to use markModified, because in most other cases the change was reflected in mongodb without using it.

这篇关于猫鼬更新嵌入式文档不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆