🌿 mongo-cache
Install
$ npm install mongo-cache // with npm
$ yarn add mongo-cache // with yarn
$ pnpm add mongo-cache // with pnpm
Usage
const { ModelWithCache } = require("mongo-cache");
const { Schema, model } = require("mongoose");
const yourSchema = new Schema({
name: String,
age: Number,
_id: String,
});
const yourModel = model("YourModelName", yourSchema);
module.exports = new ModelWithCache(yourModel);
const model = require("../path/to/your-model");
async function maybeMain() {
const doc = await model.create({ name: "John", age: 20 });
const docs = await model.getAll(true);
const docs = await model.filter({ name: "John" }, true);
const docById = await model.get(doc._id, true);
const docByQuery = await model.find({ name: "John" }, true);
const updatedDoc = await model.update(doc._id, { age: 21 });
doc.age = 21;
const updatedDoc = await model.update(doc._id, doc);
await model.delete(doc._id);
await model.deleteAll();
await model.deleteWithFilter({ name: "John" });
}
no se si tiene bugs xd