Edg*_*rka 7 mongoose mongodb graphql
我用于基于应用程序moongose的工作。目前,我尝试实现基于API。mongodbnodejsGrapqhl
我的查询graphql架构如下所示:
const schema = buildSchema(`
type Query {
predictionModels(active: Boolean): [PredictionModel]
},
type PredictionModel {
_id: ID
title: String
active: Boolean
}
`)
Run Code Online (Sandbox Code Playgroud)
但是当我使用时:
query {
predictionModels(active: true){
_id
}
}
Run Code Online (Sandbox Code Playgroud)
作为我得到的回应:
"errors": [
{
"message": "ID cannot represent value: 5a72240cf31713598588b70f",
"locations": [
{
"line": 3,
"column": 5
}
],
"path": [
"predictionModels",
0,
"_id"
]
} ....
Run Code Online (Sandbox Code Playgroud)
预测模型猫鼬架构:
const predictionModelSchema = new Schema({
title: { type: String, require: true, unique: true },
modelId: { type: String, require: true, unique: true },
description: { type: String, unique: true },
language: {type: String, enum: [ProgrammingLanguage.JS, ProgrammingLanguage.R], require: true},
estimates: [{ type : Schema.Types.ObjectId, ref: 'PredictionModelEstimate'}],
method: { type: methodType, require: true},
active: { type: Boolean, require: true}
})
Run Code Online (Sandbox Code Playgroud)
如果这是类型问题,您可以使用:
var ObjectId = require('mongoose').Types.ObjectId;
_id: new ObjectId(ID)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9038 次 |
| 最近记录: |