Complex Graphql Query with Mongodb?

Maybe not what you are looking for, but I personally would only add Apollo into my Meteor + Vue stack if I started to have other data sources in my app, other than MongoDB. Otherwise you have to do at least 3x the work. Takes some of the fun & simplicity out of Meteor, haha.

If you still want to do it, you have to 1st write your MongoDB query, just like you would in Meteor, so probably with the rawCollection() for advanced MongoDB queries & store that result in memory on the server. Then from that result, you can write your GraphQL schema, query, cache, etc. So much extra work.

From a Vue Method I often call an async Meteor Method on the Server with my complex MongoDB query, like Aggregate, and return the result directly to Vue’s data.

Here is a post that might be helpful about using rawCollection()

And you probably already have a reference for this, but here is a walk through on Apollo. Use rawCollections() in place of the MongoDB connection step. If you really wanted, because Meteor is flexible, you could follow the Apollo Tutorial exactly with a separate HTTP connection to MongoDB, but you probably wouldn’t want to go that route. If you are just playing around with Apollo to test it out, have fun, and bet you’ll come to the same conclusion about it’s extra complexity.

1 Like