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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@corluk/mongo-utils

v1.4.4

Published

This is a very lightweigth utilities package for mongodb. The motivation behind this package is making some repetitive tasks more easly.

Downloads

27

Readme

Ligthweight Utils for MongoDB

This is a very lightweigth utilities package for mongodb. The motivation behind this package is making some repetitive tasks more easly.

CollectionHelper

CollectionHelper expose api for CRUD operations on MongoDB collection which include validation before save operations using ValidationHelper

findOne: Wraps mongodb collection findOne method

   try{ 
    import Helpers from "@corluk/mongo-utils" 
    const client = new MongoClient()
    const collection = client.db().collection("test")
    const collectionHelper= Helpers.CollectionHelper(collection)
    const obj = collectionHelper.findOne({key:"value"}) 
    console.log("object" , obj)
    }catch (err){
        console.log("error", error.message)
    }
    // returns 
    // {key:"value"}

find Wraps mongodb collection find method

**

usage:

  import Helpers from "@corluk/mongo-utils" 
    
     
    try{ 
        const client = new MongoClient()
        const collection = client.db().collection("test")
        const collectionHelper= Helpers.CollectionHelper(collection)
        const obj = collectionHelper.save({key:"value"}) 
        console.log("object" , obj) 
   
    // retuns 
    // { _id : "61a2934c670ef7e01b8b392f", key:"value"}

ValidationHelper

ValidationHelper expose simple api for simple required field check if not validates throws an Error.

validate: Validates input object, throws error if validation

onValidate: Add custom function may throw error on validate.

addKey: Adds keys to check when validate called.

removeKey:
Removes key inside validation object.If you dont want to create new instance add and remove some keys in runtime.

usage:

import Helpers from "@corluk/mongodb-utils" 
const validationHelper = Helpers.ValidationHelper(["key1","key2"]) 
validationHelper.removeKey("key2")
const obj = {key1: "a" } 
validationHelper.validate(obj) // pass because we removed *key2* from 

validationHelper.addKey("key2") 
validateHelper.validate(obj) // throws error key2 added to required
fields 

validationHelper.onValidate((obj)=>{
    if(obj.items.length < 1){
        throw new Error("items length less than one")
    }
}) 
const obj = {items: []} 
validationHelper.validate(obj) // throws error 
keylist 

check test/validation.spec.js more usage examples

PaginationHelper

Enables pagination to FindCursor object. Supports: - costum collation - custom sort - pagination cycle PaginationHelper takes cursor as parameter and paginate the cursor result and returns both count of items and items array setSort Adds sort parameter as shown in https://docs.mongodb.com/drivers/node/current/fundamentals/crud/read-operations/sort/

setCollation Adds collation parameter as shown in https://docs.mongodb.com/manual/reference/method/cursor.collation/

paginate Paginates cursor for given current page and perpage arguments. Cycles back and forth.

params

  • page {number}
  • perPage {number}
  • mode {"lineer:default"| {"cycle"}}

usage

import Helpers from "@corluk/mongodb-utils"
import {MongoClient} from "mongodb"
const client = new MongoClient() 

const collectionHelper = Helpers.CollectionHelper(client.db().collection("test")) 

for(let i = 0 ; i != 100 ; i++){
    await  collectionHelper.save({value:i})
}
const paginationHelper = Helpers.PaginationHelper(cursor)
paginationHelper.setSort({value:1})
paginationHelper.setCollation({locale:"en_US", numeric})
const cursor = await collectionHelper.find({})

const page = paginationHelper.paginate(1,10) 
// returns {count:100,items:[{value:1},{value:2}...{value:10}]}