DataSources, Mongoose, and MongoDB/Apollo (Storing AND Retrieving Data)

So, I know that DataSources are meant to streamline (and improve) the process of fetching data from various types of external data sources.

When I’m working with GraphQL/MongoDB, should I be using a combination of mongoose (to STORE data) and apollo-datasource-mongodb for fetching data?

Or should I just use mongoose for everything to minimize confusion?

I didn’t know what the best practice was if you’re needing to do both things.

@czbaker Apollo Server data sources can be used for writing data as well, and the apollo-datasource-mongodb data source supports Mongoose (you can pass a Mongoose model into the MongoDataSource constructor). This means you can handle both reading/writing through your apollo-datasource-mongodb based data source, which can then use Mongoose for everything. Or if this is too many layers and you can live without the extra benefits data sources give you, then you might just want to use Mongoose directly with your resolvers.

1 Like

Oh, cool! I think I must have missed that part of the documentation, I’ll read further into it and do some experimenting locally then.

Appreciate the response!