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

simple-mongodb-wrapper

v1.0.5

Published

A simple mongodb wrapper

Downloads

3

Readme

Simple mongodb wrapper

10/17/20

Getting started

Install

npm install simple-mongodb-wrapper

then require it:

const mongo = require("simple-mongodb-wrapper");

and now its ready to use!

Usage

Tip: Use async/await

Notice:

  // You must set your mongodb connection uri
  mongo.client("YOUR_MONGDB_URI");

Working with one db

try {
  
  // opens db connection
  const db = await mongo.open("DBName");
  
  // select collection
  const collection = db.collection("viewers");
  
  // return all viewers
  const viewers = await collection.selectAll();
  
  /*
    # Shorthand method
    # mongo.selectAll(collectionName)
    const viewers = await mongo.selectAll("viewers");
  */

} catch(err) {
  console.log(err);
} finally {
  // to close all db connection
  mongo.close();
}

Working with multiple db

try {

  // opens db connection
  const db1 = await mongo.open("Db1");
  const db2 = await mongo.open("Db2");
  
  // select collection
  const users = db1.collection("users");
  const users2 = db2.collection("users");
  
  // perform commands
  await users.selectAll();
  await users2.selectAll();
  
} catch(err) {
  console.log(err);
} finally {
  mongo.close();
}

Find

collection.select([filter]);

collection.selectAll([filter]);
try {

  // returns only one
  const user = await collection.select();
  
  // returns all users
  const users = await collection.selectAll();
  
  // with filters
  // returns only renz
  const renz = await collection.select({username:"renz"});
  
  // returns all online users
  const onlineUsers = await collection.selectAll({is_online:true})
  
} catch(err) {
  console.log(err);
}

Insert

collection.insert(<data>, [options]);

collection.insertAll(<data(array)>, [options]);
try {

  // inserts renz
  await collection.insert({username:"renz",user_id:1});
  
  // inserts 3 users
  await collection.insertAll([
    { username: "abcd", user_id: 2 },
    { username: "efgh", user_id: 3 },
    { username: "ijkl", user_id: 4 }
  ]);
  
} catch(err) {
  console.log(err);
}

Update

collection.update(<filter>, <data>);

collection.updateAll(<filter>, <data>);
try {

  const filter = { username: "renz" };
  const data = { 
    $set: {
      is_online: false
    }
  };
  
  /*
    # Shorthand method
    const data = { 
      is_online: false
    };
    # it will auto add $set
    # this will work only for $set
  */
  
  // updates renz is_online status
  await collection.update(filter, data);
  
  
  const filter2 = { is_blacklisted: true };
  const data2 = { is_blacklisted: false };
  
  // unblacklist all blacklisted user
  await collection.updateAll(filter2, data2);
  
} catch(err) {
  console.log(err);
}

Delete

collection.delete([filter]);

collection.deleteAll([filter]);
try {
  
  const filter = { username: "renz" };
  
  // deletes renz
  await collection.delete(filter);
  
  const filter2 = { is_blacklisted: true };
  
  // deletes all blacklisted users
  await collection.deleteAll(filter2);
  
} catch(err) {
  console.log(err);
}

Distinct

collection.distinct(<field_name>, [filter]);
try {
  
  await collection.distinct(fieldName, filter);
 
} catch(err) {
  console.log(err);
}

Count

collection.count([filter]);
try {
  
  const totalUsers = await collection.count();
  
  // with filter
  const filter = { is_online: true };
  const totalOnlineUsers = await collection.count(filter);
  
} catch(err) {
  console.log(err);
}

Auto increment ID

mongo.getNextSequence(<counter_name>);

Notice: This will create "counters" collection

try {

  const userId = await mongo.getNextSequence("userId");
  
  await collection.insert({
    username: "doe",
    user_id: userId
  });
  
} catch(err) {
  console.log(err);
}