在linux上使用mongoose更新JSONtypes字段中的特定字段
我试图更新jsontypes字段内的特定值。
我的文档模式看起来像这样:
character { name: {type: string}, experience: {type: json} ... }
我确信经验总是包含一个带有2个字段的json对象:
{ unspent: number, total: number }
我试图做一个通用的更新方法,并在正常工作的Windows:
'update': function (itemid, update, callback) { model.update({'id': itemid}, update, {multi: false}, callback); }
更新得到一个req.body.fields对象,这是一个json对象,包含我想更新的'fields',例如
{'experience.total': 5}
这工作正常,当我在我的Windows开发框上运行它。 当我在我的linux登台服务器上尝试它时,mongoose似乎没有拿起它需要更新的东西。
我没有更新其他领域的问题(如我的例子中的“名称”)
谢谢!
如果find解决办法,在JohnnyHK的帮助下,
不要使用JSONtypes(我希望mongoose会抱怨我的模式是无效的)当你知道你的types是什么样子的时候不要使用混合types。
我改变我的模式之后:
experience: { unspent: String, total: String },
并恢复我的.markModified和.Save()function回到它的原始forms使用更新,它的工作!