当前位置:网站首页>UnhandledPromiseRejectionwarning:CastError: Cast to ObjectId failed for value
UnhandledPromiseRejectionwarning:CastError: Cast to ObjectId failed for value
2022-04-23 20:30:00 【Different 213】
UnhandledPromiseRejectionwarning:CastError: { One of the solutions }
- Cause of error : I want to query the corresponding in the database id, Delete data . But the result is an error .
The error message is :UnhandledPromiseRejectionwarning:CastError: Cast to ObjectId failed for value " 5ffbb96755245c37047691fa" at path “_id” for model "User
-
My mistake is
req.query.id
The output is the same as what I entered manually id Have the same value , But usefindOne()
The method is to query the corresponding data in the database . Then take a closer look at the terminal display , The discovery may be due to spaces . -
because
req.query.id
There is an error caused by blank space in the print result of .
As shown below, the terminal displays spaces :
The following code is used to test and draw a conclusion :
if (req.query.id.trim() === '5ffbb8e355245c37047691f4') {
console.log(' Results the same ')
} else {
console.log(req.query.id)
}
trim()
Method , Remove the spaces on both sides of the string . The output result is :” Results the same “.
版权声明
本文为[Different 213]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210550451013.html
边栏推荐
- Leetcode 20. Valid parentheses
- Customize timeline component styles
- SQL Server Connectors By Thread Pool | DTSQLServerTP plugin instructions
- selenium. common. exceptions. WebDriverException: Message: ‘chromedriver‘ executable needs to be in PAT
- 论文写作 19: 会议论文与期刊论文的区别
- LeetCode 709、转换成小写字母
- Scripy tutorial - (2) write a simple crawler
- 【PTA】L1-002 打印沙漏
- Leetcode 232, queue with stack
- 2022DASCTF Apr X FATE 防疫挑战赛 CRYPTO easy_real
猜你喜欢
Devexpress 14.1 installation record
Leetcode 542, 01 matrix
【栈和队列专题】—— 滑动窗口
Browser - learning notes
Click an EL checkbox to select all questions
Development of Matlab GUI bridge auxiliary Designer (functional introduction)
Mysql database backup scheme
On BIM data redundancy theory
Wave field Dao new species end up, how does usdd break the situation and stabilize the currency market?
Operation of numpy array
随机推荐
堡垒机、跳板机JumpServer的搭建,以及使用,图文详细
Numpy Index & slice & iteration
黑客的入侵方式你知道几种?
Some basic knowledge of devexpress report development
WordPress plug-in: WP CHINA Yes solution to slow domestic access to the official website
Commit and ROLLBACK in DCL of 16mysql
ArcGIS js api 4. X submergence analysis and water submergence analysis
[PTA] l1-006 continuity factor
Analysis of the relationship between generalized Bim and CAD under the current background
I JS deep copy and shallow copy
SQL gets the latest record of the data table
Matlab analytic hierarchy process to quickly calculate the weight
[problem solving] 'ASCII' codec can't encode characters in position XX XX: ordinal not in range (128)
6-5 string - 2 String copy (assignment) (10 points) the C language standard function library includes the strcpy function for string copy (assignment). As an exercise, we write a function with the sam
SQL Server Connectors By Thread Pool | DTSQLServerTP plugin instructions
[latex] 5 how to quickly write out the latex formula corresponding to the formula
Shanghai responded that "flour official website is an illegal website": neglect of operation and maintenance has been "hacked", and the police have filed a case
A login and exit component based on token
Numpy sort search count set
SQL: query duplicate data and delete duplicate data