【发布时间】:2017-10-04 17:44:03
【问题描述】:
我有以下字段的表格用户
id,name(varchar) ,gallery(json)
gallery包含用户上传行的图片路径,用户可以将更多图片添加到他的图库中,每张图片的图片路径以json形式存储在gallery中
这是一个示例行
id name gallery
1 blob ["test.jpg","test1.jpeg"]
这是我的代码
function(req,res){
//image path after upload
var imagePath =uploadS3();
//SELECT gallery FROM user and store to oldGallery
var oldGallery = getCurrentGallery()
var updatedGallery;
if(oldGallery==null){
updatedGallery = "[\""+imagePath+"\"]"
}else{
//concatinate the gallery row with new imagepath
updatedGallery = JSON.parse(oldGallery).push(imagePath);
}
db.query("UPDATE users SET gallery=? ",[updatedGallery],function(error,result){
});
}
但是JSON.parse(oldGallery).push(imagePath); 的问题没有解决
console.log(JSON.parse(oldGallery).push(imagePath)) 输出 2 而不是数组。
【问题讨论】:
标签: javascript mysql json node.js express