为值转换为数字失败 - GraphQL

Cast to number failed for value - GraphQL

我是 graphQL 的新手。我正在尝试使用 graphiql,并且正在尝试执行 where 我想检索年龄大于 30 岁的作者的地方。

resolver.js

Query: {

        authorGratherThan: (root, { age }) => {
            return authorModel.where({
                age: {
                    _gte: 30
                }
            });
        }

    },

graphiql 工具

{
  authorGratherThan(age:30) {
    name,
    age,
  }
}

模式模型 author.js

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;

出现此错误:

"message": "Cast to number failed for value \"{ _gte: 30 }\" at path \"age\" for model \"author\"",

只需使用 .find 而不是 .where - doc ,您的代码将变为

authorModel.find({age: { $gte: 30 }})

或者我们可以改写,

authorModel.where('age').gte(30)