Node.js 值的强制转换为数字失败-GraphQL
我是graphQL新手。我正在尝试使用graphiql,我正在尝试执行一个Node.js 值的强制转换为数字失败-GraphQL,node.js,express,graphql,graphql-js,express-graphql,Node.js,Express,Graphql,Graphql Js,Express Graphql,我是graphQL新手。我正在尝试使用graphiql,我正在尝试执行一个where,在这里我想要检索年龄大于30岁的作者 resolver.js Query: { authorGratherThan: (root, { age }) => { return authorModel.where({ age: { _gte: 30 }
where
,在这里我想要检索年龄大于30岁的作者
resolver.js
Query: {
authorGratherThan: (root, { age }) => {
return authorModel.where({
age: {
_gte: 30
}
});
}
},
import mongoose from 'mongoose';
import uuid from 'node-uuid';
const schema = mongoose.Schema;
const authorsSchema = new schema({
id: { type: String, default: uuid.v1 },
name: String,
age: Number,
books: [ String ]
});
const model = mongoose.model('author', authorsSchema);
export default model;
graphiql工具
{
authorGratherThan(age:30) {
name,
age,
}
}
模式模型
author.js
Query: {
authorGratherThan: (root, { age }) => {
return authorModel.where({
age: {
_gte: 30
}
});
}
},
import mongoose from 'mongoose';
import uuid from 'node-uuid';
const schema = mongoose.Schema;
const authorsSchema = new schema({
id: { type: String, default: uuid.v1 },
name: String,
age: Number,
books: [ String ]
});
const model = mongoose.model('author', authorsSchema);
export default model;
获取此错误:
“消息”:“对于路径处的值\“{u gte:30}\”转换为数字失败”
\模型“作者”的“年龄”
只需使用
.find
而不是。在-中,您的代码将显示出来
authorModel.find({age: { $gte: 30 }})
或者我们可以写
authorModel.where('age').gte(30)
您的数据库类型是什么?MongoDB。我已经用模式模型更新了我的问题。只需使用。查找,而不是。在那里
-,您的代码将到达authorModel。查找({age:{$gte:30})
@hoangdv请随意发布答案,这样您就可以得到分数了!非常感谢much@hoangdv仅供参考:使用where也有效,但错误是我使用的是_gte而不是$gte