将字段设置为带有mongoose的字符串
有没有比使用JSON.parse更好的方法将字段设置为带有mongoose的字符串,mongoose,Mongoose,有没有比使用JSON.parse更好的方法 userSchema.methods.incrementPlaylist = function(playlist, value) { return this.update(JSON.parse("{\"$inc\": {\"playlists." + playlist + "\": " + value + "}}")); }; 是的,请按如下方式构建更新对象: userSchema.methods.incrementPlaylist=函数(播放列
userSchema.methods.incrementPlaylist = function(playlist, value) {
return this.update(JSON.parse("{\"$inc\": {\"playlists." + playlist + "\": " + value + "}}"));
};
是的,请按如下方式构建更新对象:
userSchema.methods.incrementPlaylist=函数(播放列表,值){
var update={$inc:{};
更新。$inc['playlists.+playlist]=值;
返回此.update(更新);
};
谢谢。我不知道为什么我被对象文字所困扰,我知道我遗漏了一些东西。。。