Hi, I have the following set up to obtain an aggregated query in Mongo as part of a Graphql resolver:
return collection.rawCollection().aggregate([
{ $match : { charID: args.charID } },
{ $unwind : "$enemies" },
{ $match : { "enemies.name" : args.name } }
]))
This is the error thrown in GraphiQL: Cannot return null for non-nullable field collection.charID.
Take note that my data exists, the query works in Robo3T, and there isn’t an issue with my GraphQL schemas or anything of that sort. When I console log this entire object I see that it’s an Aggregation Cursor. How do I go about “converting” this back into something readable in Meteor’s context? .fetch() and .toArray have not worked thus far, and I’m not sure how to get around this.
Here are some images for context:
This is without aggregation:
This is with aggregation:
{
"_id" : ObjectId("5fdf16c956d6a07c2880d8a3"),
"charID" : "a",
"enemy" : [
{
"name" : "enemyA",
"weapon" : "weaponA",
"type" : "metal"
}
]
}
Should I just go with this package? GitHub - meteorhacks/meteor-aggregate: Proper MongoDB aggregations support for Meteor However, it’s not been updated in quite a while but then again it’s a very simple package.
Thanks!