当前位置:网站首页>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
边栏推荐
- Leetcode 20. Valid parentheses
- Shanghai a répondu que « le site officiel de la farine est illégal »: l'exploitation et l'entretien négligents ont été « noirs » et la police a déposé une plainte
- Development of Matlab GUI bridge auxiliary Designer (functional introduction)
- CVPR 2022 | querydet: use cascaded sparse query to accelerate small target detection under high resolution
- SQL Server Connectors By Thread Pool | DTSQLServerTP plugin instructions
- 黑客的入侵方式你知道几种?
- [stack and queue topics] - sliding window
- Leetcode 232, queue with stack
- An error is reported when sqoop imports data from Mysql to HDFS: sqlexception in nextkeyvalue
- Commande dos pour la pénétration de l'Intranet
猜你喜欢

16MySQL之DCL 中 COMMIT和ROllBACK

JDBC tool class jdbcfiledateutil uploads files and date format conversion, including the latest, simplest and easiest way to upload single files and multiple files

缓存淘汰算法初步认识(LRU和LFU)

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

Building the tide, building the foundation and winning the future -- the successful holding of zdns Partner Conference

Es keyword sorting error reason = fielddata is disabled on text fields by default Set fielddata = true on keyword in order

Sqoop imports tinyint type fields to boolean type

Commande dos pour la pénétration de l'Intranet

Plato Farm元宇宙IEO上线四大,链上交易颇高

BMP JPEG picture to vector image contourtrace
随机推荐
JS arrow function user and processing method of converting arrow function into ordinary function
RT-1052学习笔记 - GPIO架构分析
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
Alicloud: could not connect to SMTP host: SMTP 163.com, port: 25
[PTA] l1-006 continuity factor
Implementation of mypromise
Use the rolling division method to find the maximum common divisor of two numbers
Solution: NPM err! code ELIFECYCLE npm ERR! errno 1
SQL: query duplicate data and delete duplicate data
What is the difference between a host and a server?
Leetcode 74. Search two-dimensional matrix
Numpy - creation of data type and array
【PTA】L2-011 玩转二叉树
Leetcode 1346. Check whether integers and their multiples exist
An error is reported when sqoop imports data from Mysql to HDFS: sqlexception in nextkeyvalue
16MySQL之DCL 中 COMMIT和ROllBACK
bounding box iou
XXXI` Prototype ` displays prototype properties and`__ proto__` Implicit prototype properties
Matlab analytic hierarchy process to quickly calculate the weight
Commit and rollback in DCL of 16 MySQL