Socket
Socket
Sign inDemoInstall

cache-mongodb

Package Overview
Dependencies
2
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    cache-mongodb

Almacena en cache las bases de datos de MongoDB


Version published
Weekly downloads
0
Maintainers
1
Created
Weekly downloads
 

Readme

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

FAQs

Last updated on 25 Jan 2023

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc