您好,我正在尝试通过 graphQL 获取 mongoDB 集合中的一些数据,
这是我的 graphQl 架构:
type Account {
_id: String
id: String
account_id: Int
limit: Int!
products: [String]
}
type Query {
account(_id: String): [Account]
}
这是解析器返回的控制台日志
[ { _id: 5ca4bbc7a2dd94ee58162a49,
account_id: 142442,
limit: 9000,
products:
[ 'Commodity',
'CurrencyService',
'Derivatives',
'InvestmentFund',
'InvestmentStock' ],
id: '5ca4bbc7a2dd94ee58162a49' } ]
但这是从 graphiQL 返回的查询
{
"data": {
"account": [
{
"id": "5ca4bbc7a2dd94ee58162a49",
"_id": "5ca4bbc7a2dd94ee58162a49",
"account_id": null,
"limit": 9000,
"products": null
}
]
}
}
我不明白为什么我的产品和 account_id 字段返回空值,它们似乎具有正确的类型,我错过了什么吗?
最佳答案
好吧,没关系,问题出在 Mongoose 模式中,我忘记添加这些字段
const accounts = new Schema({
limit: Number,
products: [String],
account_id: Number
})
关于javascript - 无法获取字符串数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59987042/