Graphql returns null id for mongoose aggregation query, but works ok other mongoose queries.
Here is my mongoose schema:
const { Schema } = mongoose;
const ObjectId = Schema.Types.ObjectId;
const productSchema = new Schema({
_id: ObjectId,
price: Number
})
const Product = mongoose.model('Product', productSchema, 'Product')
Here is my Graphql schema:
type Product {
id: ID
price: String
}
Graphql normal query:
context.Product.findOne()
Result with console.log:
[ {
price: 10,
_id: 5d7f8efebff791dcd3bb1b69
}]
Result with graphql:
"getSearch": [
{
"id": "5d7f8efebff791dcd3bb1b69",
"price": 10,
}]
Everything is fine here. Now the problem is with aggregation query:
GraphQL query:
context.Product.aggregate(
[
{ $sample: { size: 1 } }
]
)
Result with console.log:
[ { _id: 5d7f8f23bff791dcd3bb1da3,
price: 5
}]
Result with GraphQL:
"test": [
{
"id": null",
"price": 7,
}]
The problem here is:
- the id is null
- the responses from console.log and graphql are different objects
所有评论(0)