I am looking to mongodb stitch to expose my data through graphql. I went through the initial getting started and see. the 2 queries. I want to use Altas search which requires aggregation. How do I do this from my graphql endpoint?
Hi Fred – In order to do this, you’ll want to create a custom resolver and corresponding function which will use the $search aggregation stage. One caveat for this – We currently only allow $search in functions set to run as System so you’ll want to do any permission checking in the function logic. That being said, we plan on supporting $search alongside our Rules soon.
Thanks for the response, Drew.
That is what I suspected. I am following this example create a custom resolver. I get an error on saving as shown:
Hi Fred – There is currently a bug in that form (fix pending release) causing bsonType to fail validation, you should be able to use ‘type’ instead of ‘bsonType’.
Thanks Drew. Changing to “type” worked. I have a basic custom resolver talking to function that I can hit through graphql now. Next let me see if I can get aggregate working. (I am using sample data sample_mflix)
Watched your session on MongoDB live. Nice job.
I was having trouble returning a collection (in response to an aggregation with $search and autocomplete) from my function that was called by custom resolver. I got error in graphiql.
I was missing cursor.toArray(). All good now. I have been using the sample_mflix database and movies collection. I will now implement in my own data.
Got it working.
- created realm app
- connect to my db/collection
- added rules, user (email/pw provider)
- created custom resolver, linked to my function (doing aggregate $search w/autocomplete)
- perform query in grapiql. nice! search over 550,000 docs in <1 sec. Shell says 4ms.
- authenticate with REST API email/pw and get access_token
- use external graphql tool (altair), set authorization header to Bearer <access_token>
- bob’s your uncle. graphql externally works too!