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

mongocat

v1.2.0

Published

✨ Mongocat 😺 is easy to use, configuration based Denormalization mongoose plugin for read heavy applications. Mongocat reduces write complexity too.

Downloads

27

Readme

Easy to use, configuration based Denormalization mongoose plugin for read heavy applications. Mongocat will reduce your write complexity too.

Installation

  • npm i mongocat

Why mongocat?

  • When a mid scale application are so read heavy and need an emergency solution.

Advantages

  • application performs well for many requests

  • easy to find, filter read operations

  • easy to setup

  • declarative approach

  • maintainability - you have to manage configuration only

  • very easy to sync

  • frequently requirement change is not nightmare here

  • Denormalize as you really need

  • Single source of truth. Third party source of document updates is easily synced by mongocat

Disadvantages

  • write operations are so slow

  • too much abstraction- denormalizable operations are hidden from business logic.

  • write operations are expensive & have to handle sensitively

  • it's behave like sql for strict mode. If foreign key doesn't exist write operation will fail. ( it's a good advantage for data consistency too )

Requirement

  • Firstly generate boilerplate & connect to database (mongodb via Mongoose ODM)

  • Mongoose version must be greater than 6.x.x

  • For existing project use mongocat-sync to migrate to denormable schema (We are working on it, it's not available yet)

  • Setup providers & consumers carefully

  • Follow linear approach, one collection can consume many denormalized data from many provider

  • A provider can consume many denormalized data from other providers too but never create big bang

  • Big bang creates when you are consuming from a collection at the same time provider denorbmalized data to that consumer too.

Documentation

Provider

import { provider } from 'mongocat';

const CategorySchema = new Schema(
  {
    title: String,
    slug: String,
    icon: String,
    status: String,
  },
  { timestamps: true }
);

CategorySchema.plugin(
  provider({
    toRef: 'Category',
    keyFields: ['title', 'slug', 'icon'],
    ignoredFields: ['status'],
  })
);

export const Category = model('Category', CategorySchema);
import { provider } from 'mongocat';

const UserSchema = new Schema(
  {
    name: String,
    username: String,
    email: String,
    status: String,
  },
  { timestamps: true }
);

UserSchema.plugin(
  provider({
    toRef: 'User',
    keyFields: ['name', 'username', 'email', 'status'],
  })
);

export const User = model('User', UserSchema);

Consumer

import { watchConsumer } from 'mongocat';

const BlogSchema = new Schema({
  title: String,
  slug: String,
  category: new Schema({
    _id: {
      type: Schema.Types.ObjectId,
      ref: 'Category',
    },
    title: String,
    slug: String,
    icon: String,
  }),
  status: Boolean,
});

BlogSchema.plugin(
  watchConsumer({
    toPath: 'category',
    key: '_id',
    strict: true,
    fromRef: 'Category',
    toRef: 'Blog',
    changeStreamEnabled: false, // sync updatesfrom third party source
  })
);

export const Blog = model('Blog', BlogSchema);

Frontend Payloads

  • Blog:

      {
         title: "Mongocat is joss",
         category: {
            _id: "62960300da98cc1aba3e9ee2"
         },
         status: true
      }
  {
     title: "Docker is joss",
     category: {
        _id: "62960300da98cc1aba3e9ee2"
     },
     tags: [
      { _id: "62960300da98cc1aba3e9ee2" },
      { _id: "62960300da98cc1aba3e9ee2" }
     ],
     status: true
  }