GraphQLGuide / apollo-datasource-mongodb

Apollo data source for MongoDB
MIT License
285 stars 64 forks source link

Any sample code as starter on how to use this package? #12

Closed miliu99 closed 4 years ago

miliu99 commented 4 years ago

I spent quite a bit time trying to make it connect to my mongodb but failed. Is there any sample code as starter to show how to use this package? For example, how do you connect to your db for the given url and how do you specify the collection in Datasource contructor. You mentioned using db.collection('users'), what is db here?

lorensr commented 4 years ago

Hi, I updated the README for you 😊

image

miliu99 commented 4 years ago

Thanks for your response. Did you try out this code? I believe I tried it yesterday and got an error saying client must be connected first to get db. Anyway, after struggling a couple of hours, I gave up. Instead, I now use DataSource with mongoose directly. It turns out it's much simpler and it also gives me much more control.

lorensr commented 4 years ago

Ah! Sorry, I forgot the .connect(), thank you!