Am getting this error when trying to create (insert) an object that contains an array.
If i remove the "parking" field containing the array everything works! but with it, it doesn't work, i've tried everything i could possibly think of, but i still dont understand what causes this error.
Apparently there is a problem casting to an array, but its already an arry, i dont understand.
Sample object that i insert:
{
"uid": "54654654",
"firstName": "loo",
"lastName": "laa",
"to": "ok",
"seat_no": "15",
"date_departure": "2017-12-31T18:30:00.000Z",
"date_return": "2017-12-31T18:30:00.000Z",
"traveller": "svsbsf",
"parking": [
{
"id": 1,
"numberplate": "3554654",
"brand": "bool",
"model": "baa",
"type": 1,
"$$hashKey": "object:26"
}
]
}
Here is the mongoose model
{
uid: String,
firstName: String,
lastName: String,
dob: Date,
phone: String,
address: String,
profession: String,
nationality: String,
bloodgroup: String,
parking: [ {
numberplate: String,
brand: String,
model: String,
type: String
}],
And i get this error:
"errors": {
"parking": {
"message": "Cast to Array failed for value \"[ { numberplate: '', brand: '', model: '', type: '' },\n { numberplate: '', brand: '', model: '', type: '' } ]\" at path \"parking\"",
"name": "CastError",
"stringValue": "\"[ { numberplate: '', brand: '', model: '', type: '' },\n { numberplate: '', brand: '', model: '', type: '' } ]\"",
"kind": "Array",
"value": [
{
"numberplate": "",
"brand": "",
"model": "",
"type": ""
},
{
"numberplate": "",
"brand": "",
"model": "",
"type": ""
}
],
"path": "parking",
"reason": {
"message": "Cast to string failed for value \"{ numberplate: '', brand: '', model: '', type: '' }\" at path \"parking\"",
"name": "CastError",
"stringValue": "\"{ numberplate: '', brand: '', model: '', type: '' }\"",
"kind": "string",
"value": {
"numberplate": "",
"brand": "",
"model": "",
"type": ""
},
"path": "parking"
}
}
},
"_message": "Ticket validation failed",
"message": "Ticket validation failed: parking: Cast to Array failed for value \"[ { numberplate: '', brand: '', model: '', type: '' },\n { numberplate: '', brand: '', model: '', type: '' } ]\" at path \"parking\"",
"name": "ValidationError"
}