A data source for Apollo Server v4 that integrates MongoDB via native driver collections or Mongoose models. Version 0.1.2 (stable) provides DataLoader-based batching and per-request memoization caching, with optional shared application-level caching (ttl). Key differentiators: supports both native MongoDB driver and Mongoose, provides caching for findOneById, findManyByIds, and findByFields methods, and includes a deleteFromCacheById utility. This is a fork of the original apollo-datasource-mongodb adapted for Apollo Server v4. Peer dependency on mongoose (*) required if using Mongoose models. Ships TypeScript types. Release cadence: low.
npm install apollov4-datasource-mongodbNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Sets up an Apollo Server v4 with MongoDB data source: defines a Users subclass, connects to MongoDB, and uses findOneById in a resolver.
Upgrade to Apollo Server v4 (>=4.0.0) and use apollov4-datasource-mongodb instead of the original apollo-datasource-mongodb.
Provide a single object with property 'modelOrCollection' set to either a Mongoose model or a MongoDB Collection instance.
Use findByFields for queries by non-_id fields, or ensure your Mongoose model uses _id as the primary key.
Provide ttl in seconds (e.g., { ttl: 60 }) to enable application-level caching via Apollo's cache backend.Use apollov4-datasource-mongodb instead of apollo-datasource-mongodb with Apollo Server v4.
Run 'npm install apollov4-datasource-mongodb' and ensure import path matches.
Verify import statement: 'import { MongoDataSource } from 'apollov4-datasource-mongodb''.Add super(options) in the constructor of your subclass.
Provide an options object with 'modelOrCollection' property (e.g., { modelOrCollection: collection }).