Automattic / mongoose

MongoDB object modeling designed to work in an asynchronous environment.
https://mongoosejs.com
MIT License
26.88k stars 3.83k forks source link

In-memory driver #12052

Open vkarpov15 opened 2 years ago

vkarpov15 commented 2 years ago

Prerequisites

🚀 Feature Proposal

We did some work to in 6.4 to improve support for alternative drivers: using something other than the MongoDB Node driver to store data and execute queries. One potential application is an in-memory driver: when you call create(), the in-memory driver will store the document in memory rather than storing it in MongoDB, and find() will search through the in-memory data structure rather than executing a MongoDB query.

Motivation

There's a couple of use cases for this:

  1. Much faster test suites, and easier to set up CI workflows.
  2. Easier to create a playground on mongoosejs.com (#10970), because in that case we don't have to set up a MongoDB instance or Node.js server to execute Mongoose code. We can just run the code directly in the browser.

Example

mongoose.setDriver(require('@mongoosejs/in-memory-driver'))

Nicholaiii commented 2 years ago

The Mongo memory server is a lot of overhead for testing, this would be a great feature