-
글쓴이글
-
2021년 8월 5일 22:02 #12741

김창규참가자안녕하세요 제가 mongodb에 배열 데이터를 만든 후 그곳에 배열 수정 연산자를 이용해 데이터를 넣으려 하는데 뭘 잘못 한건지 데이터가 push되지 않습니다. 코드는 아래와 같이 짰고 에러는 생기지 않습니다.
router.post('/upload',upload.single('video') ,function(req,res){
if( req.cookies.key ){
jwt.verify( req.cookies.key,process.env.SECRET_KEY ,function(err,decoded){
if( err ) return err;
userSchema.updateOne({ email: decoded.user_id },{ $push: { videoUrl : req.file.location },function(err,result){
if( err ) return;
console.log(result);
}});
});
}else{
return res.status(400).json({ message: '로그인 해주십시오' });
}
})2021년 8월 6일 14:53 #12793
codingapple키 마스터{ email: decoded.user_id } 이거와 일치하는 문서를 업데이트하라고 명령중인데
이 문서를 못찾은게 아닐까요 decoded.user_id가 원하는 값이 나오는지 출력해봅시다
2021년 8월 6일 15:17 #12796
김창규참가자updateOne으로 찾으면 result 값이 아래와 같이 뜨기는 합니다;;
{
n: 1,
nModified: 0,
opTime: {
ts: Timestamp { _bsontype: 'Timestamp', low_: 1, high_: 1628230287 },
t: 60
},
electionId: 7fffffff000000000000003c,
ok: 1,
'$clusterTime': {
clusterTime: Timestamp { _bsontype: 'Timestamp', low_: 1, high_: 1628230287 },
signature: { hash: [Binary], keyId: [Long] }
},
operationTime: Timestamp { _bsontype: 'Timestamp', low_: 1, high_: 1628230287 }
}2021년 8월 6일 17:40 #12807
codingapple키 마스터{ $push: { videoUrl : req.file.location } 여기 뒤에 } 이거 하나가 빠진듯요?
2021년 8월 6일 18:20 #12809
김창규참가자그래도 해결이 안 돼네요 혹시 스키마 작성한게 틀린건가 해서 스키마 작성 한 것도 남겨봅니다 ㅠ
const user = new mongoose.Schema({
email: {
type: String,
require: true,
unique: true,
trim: true,
},
pw: {
type: String,
require: true,
trim: true
},
name: {
type: String,
require: true,
trim: true
},
salt: {
type: String,
trim: true,
},
videoUrl: [String]
}); -
글쓴이글
- 답변은 로그인 후 가능합니다.
