🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

cache-mongodb

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

cache-mongodb

Almacena en cache las bases de datos de MongoDB

1.0.4
unpublished
latest
npm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

🌿 mongo-cache

Install

$ npm install mongo-cache // with npm
$ yarn add mongo-cache // with yarn
$ pnpm add mongo-cache // with pnpm

Usage

// your-model.js
const { ModelWithCache } = require("mongo-cache");
const { Schema, model } = require("mongoose");

const yourSchema = new Schema({
  name: String,
  age: Number,
  _id: String, // set id if you want to use it as cache key
});

const yourModel = model("YourModelName", yourSchema);

module.exports = new ModelWithCache(yourModel);
// idk.js
const model = require("../path/to/your-model");

async function maybeMain() {
  // create document
  const doc = await model.create({ name: "John", age: 20 });

  // get all documents
  const docs = await model.getAll(true); // true to skip cache

  // get all documents with filter
  const docs = await model.filter({ name: "John" }, true); // true to skip cache

  // get document by id
  const docById = await model.get(doc._id, true); // true to create if not exists

  // get document by query
  const docByQuery = await model.find({ name: "John" }, true); // true to create if not exists

  // update document
  const updatedDoc = await model.update(doc._id, { age: 21 });
  /* or... */
  doc.age = 21;
  const updatedDoc = await model.update(doc._id, doc);
  /* ❌ if you use <Document>.save(), the document won't be cached ❌ */

  // delete document
  await model.delete(doc._id);

  // delete all documents
  await model.deleteAll();

  // delete all documents with filter
  await model.deleteWithFilter({ name: "John" });
}

no se si tiene bugs xd

Keywords

mongoose

FAQs

Package last updated on 25 Jan 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts