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

mongo-query-utils

v1.2.0

Published

A simple mongo query builder for node.js

Downloads

2

Readme

🔒 mongo-query-utils

A simple mongo query builder for node.js for Node/Express.js.

🚀 Features

Create Documents – Create a new document and save to database
Fetch Documents – Collect all or necessary documents from the database
Update Documents – Update all or specific document(s) from the database
Delete Documents – Remove documents from the database
Join Documents – Join documents from different tables


📦 Installation

npm install mongo-query-utils

🚀 Usage

1️⃣ Import the Module

const {
  fetchAll,
  fetchOne,
  generate,
  fetchById,
  patchOneAndUpdate,
  patchByIdAndUpdate,
  patchOne,
  patchMany,
  replaceOne,
  removeOne,
  removeMany,
  summarize,
} = require("mongo-query-utils");

Create a New Document

const Table = require("your-schema");
const document = {
  first_name: "Sample",
  last_name: "Test",
};
const newDoc = await generate(document, Table);
console.log(Table);

🔍 Fetch a Single Document

Fetch a single document based on the provided query.

const query = { email: "[email protected]" };
const user = await fetchOne(query, User);
console.log(user); // { _id: 123, email: "[email protected]", name: "John Doe" }

🆔 Fetch Document by ID

Retrieve a document using its unique _id.

const id = "60d5f9e8f1c2b4a3d8f5e7c6";
const document = await fetchById(id, Table);
console.log(document);

✏️ Update Documents

Update the first document that matches the query.

Update a Single Document

const query = { email: "[email protected]" };
const update = { name: "Updated Name" };
const updatedDoc = await patchOneAndUpdate(query, update, User);
console.log(updatedDoc);

Update a Document by ID

const id = "60d5f9e8f1c2b4a3d8f5e7c6";
const update = { status: "Active" };
const updatedDoc = await patchByIdAndUpdate(id, update, Table);
console.log(updatedDoc);

Update Multiple Documents

const query = { status: "Pending" };
const update = { status: "Completed" };
const updatedDocs = await patchMany(query, update, Table);
console.log(updatedDocs);

🔄 Replace a Document

Replace an entire document with new data.

const query = { email: "[email protected]" };
const newDocument = { email: "[email protected]", name: "New Name" };
const replacedDoc = await replaceOne(query, newDocument, User);
console.log(replacedDoc);

🗑️ Delete Documents

Delete a Single Document

const query = { email: "[email protected]" };
const deletedDoc = await removeOne(query, User);
console.log(deletedDoc);

Delete Multiple Documents

const query = { status: "Inactive" };
const deletedDocs = await removeMany(query, User);
console.log(deletedDocs);

🔗 Join Collections

Join documents from two collections using $lookup.

const pipeline = [
  {
    $match: {_id: 'sample_id'}
    $lookup: {
      from: "orders",        // Collection to join
      localField: "_id",      // Field in primary collection
      foreignField: "userId", // Field in foreign collection
      as: "userOrders"        // Output array
    }
  }
];
const usersWithOrders = await summarize(pipeline, User);
console.log(usersWithOrders);

🛠️ Options

Each function accepts an optional third parameter for customization:

const options = { sort: { createdAt: -1 }, limit: 10 };
const latestUsers = await fetchAll({}, User, options);
console.log(latestUsers);

📜 License

MIT License. See LICENSE for details.

📌 Author: Ryan Charles Alcaraz (github)