当前位置:网站首页>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.idThe 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.idThere 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
边栏推荐
- BMP JPEG picture to vector image contourtrace
- Go zero framework database avoidance Guide
- I JS deep copy and shallow copy
- Use the rolling division method to find the maximum common divisor of two numbers
- Vscode download speed up
- PostgreSQL basic functions
- PIP installation package reports an error. Could not find a version that satisfies the requirement pymysql (from versions: none)
- DNS cloud school | quickly locate DNS resolution exceptions and keep these four DNS status codes in mind
- 高薪程序员&面试题精讲系列91之Limit 20000加载很慢怎么解决?如何定位慢SQL?
- 三十.什么是vm和vc?
猜你喜欢

The construction and use of Fortress machine and springboard machine jumpserver are detailed in pictures and texts

Installation and use of NVM

Mysql database backup scheme

LeetCode 116. Populate the next right node pointer for each node

JS arrow function user and processing method of converting arrow function into ordinary function

Recommend an open source free drawing software draw IO exportable vector graph

C migration project record: modify namespace and folder name

Rt-1052 learning notes - GPIO architecture analysis

Development of Matlab GUI bridge auxiliary Designer (functional introduction)

Don't bother tensorflow learning notes (10-12) -- Constructing a simple neural network and its visualization
随机推荐
Solve the Chinese garbled code of URL in JS - decoding
Leetcode 20. Valid parentheses
Paper writing 19: the difference between conference papers and journal papers
16MySQL之DCL 中 COMMIT和ROllBACK
Recognition of high-speed road signs by Matlab using alexnet
【PTA】L2-011 玩转二叉树
Latest investigation and progress of building intelligence based on sati
[problem solving] 'ASCII' codec can't encode characters in position XX XX: ordinal not in range (128)
JS arrow function user and processing method of converting arrow function into ordinary function
Recommend an open source free drawing software draw IO exportable vector graph
ArcGIS js api 4. X submergence analysis and water submergence analysis
Automatically fill in body temperature and win10 task plan
bounding box iou
Mathematical modeling column | Part 5: MATLAB optimization model solving method (Part I): Standard Model
LeetCode 709、转换成小写字母
Vscode download speed up
Es index (document name) fuzzy query method (database name fuzzy query method)
LeetCode 20、有效的括号
Go zero framework database avoidance Guide
Leetcode 1337. Row K with the weakest combat effectiveness in the matrix