我一直在努力看并解决这一问题,但最终却没有找到任何相关的解决办法。需要更多的投入和建议来解决这个问题。请检查我下面的代码详细信息。我使用的是Express GraphQL,和猫鼬版本:^5.9.25
我用GraphQL来做这个,
下面的
是我的查询请求
query {
getTrainsbySetno(details:"233"){
_id
setno
train_no
start_station_code
end_station_code
route_code
train_type
start_on
change_on
halts_at
createdAt
updatedAt
}
}My GraphqL查询响应
{
"errors": [
{
"message": "Cast to string failed for value \"{ details: '233' }\" at path \"setno\" for model \"Trains\"",
"locations": [
{
"line": 55,
"column": 3
}
],
"path": [
"getTrainsbySetno"
]
}
],
"data": {
"getTrainsbySetno": null
}
}下面的
是我的Resolver
getTrainsbySetno: async (details) => {
try {
const result = await Trains.find({$or:[{setno: details },{train_no: details}]});
console.log(result);
return result.map(res => {
return { ...res._doc, _id: res.id };
});
} catch (err) {
throw err;
}
},下面是我的模式:
:
const Schema = mongoose.Schema;
const trainsSchema = new Schema ({
setno : {
type: String,
required: true
},
train_no : {
type: String,
required: true
},
start_station_code : {
type: String,
required: false
},
end_station_code : {
type: String,
required: true
},
route_code : {
type: String,
required: true
},
train_type : {
type: String,
required: true
},
start_on : {
type: String,
required: true
},
change_on : {
type: String,
required: true
},
halts_at : {
type: String,
required: true
}
},
{ timestamps: true }
);
module.exports = mongoose.model('Trains', trainsSchema);发布于 2020-11-04 06:39:20
在getTrainsbySetno方法中,参数"details“是一个对象。因此,要获得details obj的值,我们需要用"details.details“替换细节。
https://stackoverflow.com/questions/64674333
复制相似问题