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 🙏

© 2025 – Pkg Stats / Ryan Hefner

pnk-node-mongo

v1.1.6

Published

A lightweight Node.js MongoDB utility library providing CRUD operations, pagination, filtering, sorting, and aggregation with Mongoose support.

Readme

Pnk-Node-Mongo

A reusable and lightweight Node.js module that helps you easily integrate Mongoose-based MongoDB queries with pagination, filtering, sorting, searching, field selection, and update utilities.

🚀 Installation

npm install pnk-node-mongo

You can use this Library for below operations in Node with MongoDB

  1. findOne
  2. find with Pagination
  3. updateMany
  4. updateOne
  5. findOneAndUpdate etc
  6. insert one and many

📦 Usage

const { PnkAddNew, PnkFetchAll, PnkFetchOne, PnkUpdate, PnkFindAndModify, PnkResult, PnkResultSummary } = require('pnk-node-mongo');

Fetch Example

//Example with find (use with Post always for Search and Filters)

const { PnkFetchAll } = require('pnk-node-mongo');
GetAllUsers = async (req, res) => {
  try {
    const options = {
      page: req.body.set_no || 1,
      per_set: req.body.per_set || 10,
      search_data: req.body.search ? { user_name: req.body.user_name } : {},
      sorting: { createdAt: -1 },
      // specific_data: ['user_name', 'user_email'],
      // data_except_few: ['user_password'],
    };
    const result = await PnkFetchAll("userlistresponse", "documentName in mongodb", options);
	console.log(result);
    res.status(200).json(result);
  } catch (err) {
    console.log(err);
    res.status(500).json({ error: err.message });
  }
};

You can update parameters as per use cases.

Find and Modify Example

// Example with findAndModify (use with Post/Put)
const { PnkFindAndModify } = require('pnk-node-mongo');

FindAndModifyUser = async (req, res) => {
  try {
    const result = await PnkFindAndModify({
      respKey: 'userupdateresponse',
      model: "documentName in mongodb",
      filter: { user_mobile: "0000000000" },
      update: { user_name: 'prabhash' },
      options: { _id: -1 },
      new_data: true,
      onlyFields: "user_name, user_email", // <-- return only selected fields
      // exceptFields: "user_password, user_origin"    // <-- or exclude this field instead
      resp: false
    })
	console.log(result);
    res.status(200).json({ success: true, result });
  } catch (err) {
    res.status(400).json({ success: false, message: err.message });
  }
};

* If you need updated data in response then set new_data = true
* If you need data in json format then send resp = true

Update Example

// Example with updateOne and updateMany (use with Post/Put)
const { PnkUpdate } = require('pnk-node-mongo');

exports.UpdateUser = async (req, res) => {
  try {
    const result = await PnkUpdate({
      respKey: 'userupdateresponse',
      model: 'documentName in mongodb',
      filter: { user_mobile: "7795834234" },
      updateData: { user_name: 'prabhash' },
      multi: false,
      options: { new: false }
    });
    res.status(200).json({ success: true, result });
  } catch (err) {
    res.status(400).json({ success: false, message: err.message });
  }
};

* If you need multi update then sent true otherwise false
* If you need data to be upserted (insert new) if not found then sent options: { new: true }

Insert Example

// Example with Insert one and Many (use with Post/Put)
const { PnkAddNew } = require('pnk-node-mongo');

exports.UpdateUser = async (req, res) => {
  try {
	const user_data = {
      user_name: 'test',
      user_full_name: 'prabhash',
      user_email: '[email protected]'
      user_status: 1,
    };
	
    const result = await PnkAddNew(
	{ respKey: "userentryresponse",
	model: 'documentName in mongodb',
	data: user_data,
	multi: false,
	resp: true });
	
    res.status(200).json({ success: true, result });
  } catch (err) {
    res.status(400).json({ success: false, message: err.message });
  }
};

* If you need multi then data should be in Array only and multi : true

✨ Features

  • Paginated fetch with search, filter, and sort support
  • Select specific fields or exclude them
  • Flexible update operation (single/multi)
  • Auto response formatting (optional)

🧪 Testing

npm test

📜 License

MIT