我想用其他对象替换对象“习惯”。例如,我想将习惯:{1:{“名称”:“喝水”,记录:[[0],[1]]}}替换为习惯:{1:{“名称”:“喝水” , 记录:[[0],[1]]}, 2:{"名称":"拉伸", "记录":[[0],[1]]}}。
var User=require("mongoose").model("User"); //user schema
...
router.post('/', async (req,res,next)=>{ //req: {username, total, board:{index:{habitname, record:[[날짜, 요일, check]...]}}}
console.log("backedn board");
var username=req.body.username;
var habit_list=req.body.board;
console.log(req.body.board);
var info=req.body;
//mongodb: {username, password, habit:{1:{}, 2:{}}}
try{
//const user=await User.findOne({username:username});
User.update({'username':username}, {'habit':habit_list});
console.log("update user habit!");
res.send(info);
}
catch(error){
console.log("fail to save data")
res.send(error);
}
但它不起作用......
慕容708150
相关分类