같은코드인데 에러가납니다.
211
Jon
작성한 질문수 53
0
{
"err": "The path 'comments' must exist in the document in order to apply array updates."
}
모델은 강의코드와 같은상태이고
route 의 put부분도 똑같은 상태입니다. 해당에러로 구글링을 해보았지만 잘 이해가안되어서 질문을 드립니다 !!
혹시 이런경우에는 어떤것을 의심해야하나요? Blog Model에 comments 가 정상적으로 있는데 저 에러가 나서요...!
userRouter.put('/:userId', async (req, res) => {
try {
const { userId } = req.params;
if (!mongoose.isValidObjectId(userId))
return res.status(400).send({ err: 'invalid userId' });
const { age, name } = req.body;
if (!age && !name)
return res.status(400).send({ err: 'age or name is required' });
if (age && typeof age !== 'number')
return res.status(400).send({ err: 'age must be a number' });
if (name && typeof name.first !== 'string' && typeof name.last !== 'string')
return res.status(400).send({ err: 'first and last name are strings' });
// let updateBody = {};
// if(age) updateBody.age = age;
// if(name) updateBody.name = name;
// const user = await User.findByIdAndUpdate(userId, updateBody, { new: true });
const user = await User.findById(userId);
if (age) user.age = age;
if (name) {
user.name = name;
await Promise.all([
Blog.updateMany({ 'user._id': userId }, { 'user.name': name }),
Blog.updateMany(
{},
{ 'comments.$[comment].userFullName': `${name.first} ${name.last}` },
{ arrayFilters: [{ 'comment.user': userId }] }
),
]);
}
await user.save();
return res.send({ user });
} catch (err) {
console.log(err);
return res.status(500).send({ err: err.message });
}
});
답변 1
option usecreateindex is not supported 오류 나면은
0
147
1
Schemaless 특성을 재생시 검은화면이 나와요
0
241
1
user 내장 시 ref 필드 필요성
0
240
1
await 관련해서 질문드릴게 있습니다!!
0
293
2
섹션6의 3번째 강의 faker파일이 어디있나요?
0
309
1
$elemMatch 질문이 있습니다.
0
248
1
DB 업데이트에 실패했을 상황에서 대처는 어떻게 할 수 있나요.
2
767
2
블로그에 user 데이터를 추가하는 방법에 대해서
0
238
1
blog 데이터 생성시 user 관련 오류
0
352
1
age 예외 처리를 별도로 하신 이유가 궁금합니다.
2
302
2
delete 메소드가 많은 이유가 궁금합니다.
0
182
1
unique validation 처리
0
297
1
updateMany에서 user._id를 못찾는 상황
1
397
1
find() 가 리턴하는 instance member
1
432
3
몽고 db를 백업방법을 부탁합니다.
0
604
1
인덱스 생성시점
0
713
1
$pull 문법에 대한 질문
0
361
1
comment의 id가 생성되는 시점
1
303
1
리팩토링 강의에서 라우터 리팩토링 전개연산자(...)
1
316
1
session.abortTransaction()에 대한 실제 예시 문의
0
289
1
섹션9 Computed Fields 강의에서, 다음 강의 가기 전 빠진부분
-1
411
1
faker 패키지 취약성 이슈
1
488
1
라우터 리팩토링
0
345
1
섹션4 진행중, mongoose 질문
0
312
1





