npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

laraqm

v1.2.0

Published

Quick Mongodb wrapper for beginners that provides key-value based interface.

Downloads

1

Readme

QuickMongo

Quick Mongodb wrapper for beginners that provides key-value based interface.

Added an IN MEMORY CACHE by using this.cache = new Map(); You can't access them, and just use it as quickmongo The File handles all of the caching by itsself! (also resetting the cache if something changes in the db......... Fastens it up by ~90-125% (if you do many .set() requests == POST) Fastens it up by over 300% (if you do many .get() requests == GET)

Why is this good?

You do not spam mongodb, and it's userfriendly, you don't need something like redis or cache-manager NOTE: It's the simplest way of caching, and only applies if u got the request ONCE, so it's not "that efficient" but good enough if u plan on running ur app/programm for several hours!

to install it: npm install https://github.com/Tomato6966/quickmongo

EXTRAS ADDED:

Getting things out of the cache will work until the max. cache duration is reached

// How to change them
// change the max. cache duration for db.ping()
process.env.DB_cache_ping = 10_000; // Delete the cache after X ms | < 0 === never delete [DEFAULT: 60_000], -1 (or less) == disabled cache
// change the max. cache duration for db.get("key", [optional: ForceFetch <true/false>])
process.env.DB_cache_get = 0; // Delete the cache after X ms | 0 === never delete [DEFAULT: 300_000], -1 (or less) == disabled cache
// change the max. cache duration for db.all([optional: ForceFetch <true/false>])
process.env.DB_cache_all = 0; // Delete the cache after X ms | 0 === never delete [DEFAULT: 600_000], -1 (or less) == disabled cache

const { Database } = require("quickmongo"); // npm i https://github.com/Tomato6966/quickmongo
const mongoUri = process.env.mongoUri;
const db = new Database(mongoUri);

// CHANGES FOR THE .get() method
db.get("key"); // 1. Time getting --> Fetch from db
db.get("key"); // 2. Time getting --> Get from cache (instant) 
db.get("key", true) // 3. Time getting --> Force-fetch from db (you can add ,true for fetching)

// CHANGES FOR THE .ping() METHOD
db.ping(); // 1. Time getting --> PING THE db
db.ping(); // 2. Time getting --> Get the last ping, which u got before (instant) ( will work until the max. cache duration is reached )
db.ping(true) // 3. Time getting --> Force-fetch from db (you can add ,true for fetching)

// CHANGES FOR THE .all() METHOD
db.all(); // 1. Time getting --> Fetch from the db
db.all(); // 2. Time getting --> Get it from the cache (intsant)
db.all(true) // 3. Time getting --> Force-fetch from db (you can add , true for fetching)

Suggestions:

When creating the Database, add mongoose options, to spread the load on your db!

const { Database } = require("quickmongo"); // npm i https://github.com/Tomato6966/quickmongo
const mongoUri = process.env.mongoUri;
const db = new Database(mongoUri, {
    useUnifiedTopology: true, // allow pools
    maxPoolSize: 100, // maximum spreader
    minPoolSize: 50, // minimum spreader
    writeConcern: "majority", // writer before get
});

Tests:

If you're interested to see it changes test this:

const { Database } = require("quickmongo"); // npm i https://github.com/Tomato6966/quickmongo
const mongoUri = process.env.mongoUri;

process.env.DB_cache_ping = 10_000; // allow the cache to be just 10 sec in there...

const db = new Database(mongoUri, {
    useUnifiedTopology: true, // allow pools
    maxPoolSize: 100, // maximum spreader
    minPoolSize: 50, // minimum spreader
    writeConcern: "majority", // writer before get
});
// first time
setTimeout(async() => console.log(`Ping: ${await db.ping()}`), 1_000) // fetch from the db (DIRECT VALUE FROM MONGODB)
// 2 times from cache (will be instant when the timeout executes)
setTimeout(async() => console.log(`Ping: ${await db.ping()}`), 5_000) // cache
setTimeout(async() => console.log(`Ping: ${await db.ping()}`), 8_000) // cache
// cache ranned out, after first fetch, so fetch it again ( you cahgned process.env.DB_cache_ping to 10secs)
setTimeout(async() =>console.log(`Ping: ${await db.ping()}`), 11_000) // fetch (DIRECT VALUE FROM MONGODB)
// get it from the cache again as it's already in there
setTimeout(async() => console.log(`Ping: ${await db.ping()}`), 12_000) // get from cache
// force-fetch from the DB (DIRECT VALUE FROM MONGODB)
setTimeout(async() => console.log(`Ping: ${await db.ping(true)}`), 12_000) 

Installing

npm install --save https://github.com/Tomato6966/quickmongo # for the adjusted one with cache
npm install --save quickmongo # for the original without cache

Documentation

https://quickmongo.js.org

Features

  • Beginner friendly
  • Asynchronous
  • Dot notation support
  • Key-Value like interface
  • Easy to use
  • TTL (temporary storage) supported

Example

import { Database } from "quickmongo";

const db = new Database("mongodb://localhost:27017/quickmongo");

db.on("ready", () => {
    console.log("Connected to the database");
    doStuff();
});

// top-level awaits
await db.connect(); 

async function doStuff() {
    // Setting an object in the database:
    await db.set("userInfo", { difficulty: "Easy" });
    // -> { difficulty: 'Easy' }

    // Pushing an element to an array (that doesn't exist yet) in an object:
    await db.push("userInfo.items", "Sword");
    // -> { difficulty: 'Easy', items: ['Sword'] }

    // Adding to a number (that doesn't exist yet) in an object:
    await db.add("userInfo.balance", 500);
    // -> { difficulty: 'Easy', items: ['Sword'], balance: 500 }

    // Repeating previous examples:
    await db.push("userInfo.items", "Watch");
    // -> { difficulty: 'Easy', items: ['Sword', 'Watch'], balance: 500 }
    await db.add("userInfo.balance", 500);
    // -> { difficulty: 'Easy', items: ['Sword', 'Watch'], balance: 1000 }

    // Fetching individual properties
    await db.get("userInfo.balance"); // -> 1000
    await db.get("userInfo.items"); // -> ['Sword', 'Watch']

    // remove item
    await db.pull("userInfo.items", "Sword");
    // -> { difficulty: 'Easy', items: ['Watch'], balance: 1000 }

    // set the data and automatically delete it after 1 minute
    await db.set("foo", "bar", 60); // 60 seconds = 1 minute

    // fetch the temporary data after a minute
    setTimeout(async () => {
        await db.get("foo"); // null
    }, 60_000);
}

Created and maintained by CesiumLabs

Discord Support

CesiumLabs