CastError: Cast to ObjectId failed for value "undefined" (type string) at path "_id" for model "User"
at ObjectId.cast (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\schema\objectid.js:250:11)
at SchemaType.applySetters (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\schematype.js:1220:12)
at SchemaType.castForQuery (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\schematype.js:1632:15)
at ObjectId.handleSingle (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\schematype.js:1562:15)
at SchemaType.castForQuery (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\schematype.js:1629:20)
at cast (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\cast.js:334:39)
at Query.cast (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\query.js:4911:12)
at Query._castConditions (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\query.js:2232:10)
at model.Query._find (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\query.js:2258:8)
at model.Query.exec (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\query.js:4430:28) {
stringValue: '"undefined"',
messageFormat: undefined,
kind: 'ObjectId',
value: 'undefined',
path: '_id',
reason: BSONError: Argument passed in must be a string of 12 bytes or a string of 24 hex characters or an integer
at new ObjectId (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\bson\lib\bson.cjs:2055:23)
at castObjectId (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\cast\objectid.js:25:12)
at ObjectId.cast (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\schema\objectid.js:248:12)
at SchemaType.applySetters (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\schematype.js:1220:12)
at SchemaType.castForQuery (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\schematype.js:1632:15)
at ObjectId.handleSingle (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\schematype.js:1562:15)
at SchemaType.castForQuery (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\schematype.js:1629:20)
at cast (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\cast.js:334:39)
at Query.cast (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\query.js:4911:12)
at Query._castConditions (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\query.js:2232:10),
valueType: 'string',
model: Model { User }
}
CastError: Cast to ObjectId failed for value "undefined" (type string) at path "_id" for model "User"
at ObjectId.cast (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\schema\objectid.js:250:11)
at SchemaType.applySetters (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\schematype.js:1220:12)
at SchemaType.castForQuery (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\schematype.js:1632:15)
at ObjectId.handleSingle (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\schematype.js:1562:15)
at SchemaType.castForQuery (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\schematype.js:1629:20)
at cast (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\cast.js:334:39)
at Query.cast (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\query.js:4911:12)
at Query._castConditions (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\query.js:2232:10)
at model.Query._find (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\query.js:2258:8)
at model.Query.exec (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\query.js:4430:28) {
stringValue: '"undefined"',
messageFormat: undefined,
kind: 'ObjectId',
value: 'undefined',
path: '_id',
reason: BSONError: Argument passed in must be a string of 12 bytes or a string of 24 hex characters or an integer
at new ObjectId (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\bson\lib\bson.cjs:2055:23)
at castObjectId (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\cast\objectid.js:25:12)
at ObjectId.cast (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\schema\objectid.js:248:12)
at SchemaType.applySetters (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\schematype.js:1220:12)
at SchemaType.castForQuery (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\schematype.js:1632:15)
at ObjectId.handleSingle (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\schematype.js:1562:15)
at SchemaType.castForQuery (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\schematype.js:1629:20)
at cast (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\cast.js:334:39)
at Query.cast (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\query.js:4911:12)
at Query._castConditions (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\query.js:2232:10),
valueType: 'string',
model: Model { User }
}
السؤال
محمود سعداوي2
السلام عليكم.
الرجاء توضيح الخطأ التالي.
CastError: Cast to ObjectId failed for value "undefined" (type string) at path "_id" for model "User" at ObjectId.cast (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\schema\objectid.js:250:11) at SchemaType.applySetters (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\schematype.js:1220:12) at SchemaType.castForQuery (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\schematype.js:1632:15) at ObjectId.handleSingle (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\schematype.js:1562:15) at SchemaType.castForQuery (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\schematype.js:1629:20) at cast (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\cast.js:334:39) at Query.cast (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\query.js:4911:12) at Query._castConditions (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\query.js:2232:10) at model.Query._find (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\query.js:2258:8) at model.Query.exec (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\query.js:4430:28) { stringValue: '"undefined"', messageFormat: undefined, kind: 'ObjectId', value: 'undefined', path: '_id', reason: BSONError: Argument passed in must be a string of 12 bytes or a string of 24 hex characters or an integer at new ObjectId (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\bson\lib\bson.cjs:2055:23) at castObjectId (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\cast\objectid.js:25:12) at ObjectId.cast (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\schema\objectid.js:248:12) at SchemaType.applySetters (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\schematype.js:1220:12) at SchemaType.castForQuery (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\schematype.js:1632:15) at ObjectId.handleSingle (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\schematype.js:1562:15) at SchemaType.castForQuery (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\schematype.js:1629:20) at cast (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\cast.js:334:39) at Query.cast (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\query.js:4911:12) at Query._castConditions (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\query.js:2232:10), valueType: 'string', model: Model { User } } CastError: Cast to ObjectId failed for value "undefined" (type string) at path "_id" for model "User" at ObjectId.cast (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\schema\objectid.js:250:11) at SchemaType.applySetters (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\schematype.js:1220:12) at SchemaType.castForQuery (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\schematype.js:1632:15) at ObjectId.handleSingle (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\schematype.js:1562:15) at SchemaType.castForQuery (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\schematype.js:1629:20) at cast (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\cast.js:334:39) at Query.cast (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\query.js:4911:12) at Query._castConditions (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\query.js:2232:10) at model.Query._find (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\query.js:2258:8) at model.Query.exec (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\query.js:4430:28) { stringValue: '"undefined"', messageFormat: undefined, kind: 'ObjectId', value: 'undefined', path: '_id', reason: BSONError: Argument passed in must be a string of 12 bytes or a string of 24 hex characters or an integer at new ObjectId (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\bson\lib\bson.cjs:2055:23) at castObjectId (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\cast\objectid.js:25:12) at ObjectId.cast (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\schema\objectid.js:248:12) at SchemaType.applySetters (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\schematype.js:1220:12) at SchemaType.castForQuery (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\schematype.js:1632:15) at ObjectId.handleSingle (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\schematype.js:1562:15) at SchemaType.castForQuery (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\schematype.js:1629:20) at cast (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\cast.js:334:39) at Query.cast (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\query.js:4911:12) at Query._castConditions (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\mongoose\lib\query.js:2232:10), valueType: 'string', model: Model { User } }
مع العلم الكود يعمل بصفة عادية.
شكرا لكم.
2 أجوبة على هذا السؤال
Recommended Posts
انضم إلى النقاش
يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.