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

my-mongo

v1.2.9

Published

Handles MongoDb connections (connect function). Lets redefine functions.

Downloads

4

Readme

Introduction

my_mongo handles MongoDb connections (via the connect function). If a connection exist, use it, otherwise create a new connection. You can define your own functions and redefine existing functions.

Installation

npm install my-mongo

Work in progress, current implemented functions :

mongo.setDebug
mongo.doit
mongo.connect        (uses MongoClient.connect)
mongo.disconnect     (uses db.close)
mongo.insert         (uses db.collection(c).insert)
mongo.update         (uses db.collection(c).update)
mongo.remove         (uses db.collection(c).remove)
mongo.removeById     (uses mongo.remove)
mongo.findOne        (uses db.collection(c).findOne)
mongo.find           (uses db.collection(c).find)
mongo.findById       (uses mongo.findOne)
mongo.dropCollection (uses db.collection(c).drop)

Example :

var my_mongo = require('my-mongo')
var mongo = new my_mongo("mongodb://localhost:27017/db_name", "collection_name");
mongo.setDebug(true);

doc1 = { "name": "doc1", "text": "", "left": 10, "top": 10};
doc2 = { "name": "doc2", "text": "", "left": 20, "top": 20};
doc3 = { "name": "doc3", "text": "", "left": 30, "top": 30};

mongo.insert([doc1, doc2, doc3], function(err, results){
  assert.equal(null, err);
  console.log(results);

  mongo.update({"name": "doc1"}, { "left": 11, "top": 11}, function(err, results){
    console.log(results.result);
  });

  mongo.remove({"name": "doc2"}, function(err, results){
    console.log(results.result);
  });

  mongo.find({}, {}, function(err, results){
    console.log(results);

    mongo.dropCollection(function(err, results){

      mongo.disconnect(function(err){
      })
    });
  });
});

Results :

Connecting to db
Connecting to db
{ result: { ok: 1, n: 3 },
  ops:
   [ { name: 'doc1',
       text: '',
       left: 10,
       top: 10,
       _id: 568a95850e1ae43c1b4be215 },
     { name: 'doc2',
       text: '',
       left: 20,
       top: 20,
       _id: 568a95850e1ae43c1b4be216 },
     { name: 'doc3',
       text: '',
       left: 30,
       top: 30,
       _id: 568a95850e1ae43c1b4be217 } ],
  insertedCount: 3,
  insertedIds:
   [ 568a95850e1ae43c1b4be215,
     568a95850e1ae43c1b4be216,
     568a95850e1ae43c1b4be217 ] }
{ ok: 1, nModified: 1, n: 1 }
{ ok: 1, n: 1 }
[ { _id: 568a95850e1ae43c1b4be215,
    name: 'doc1',
    text: '',
    left: 11,
    top: 11 },
  { _id: 568a95850e1ae43c1b4be217,
    name: 'doc3',
    text: '',
    left: 30,
    top: 30 } ]
Closing connection to db

How-to redefine a function :

mongo.insert = function (docs)
{
  mongo.doit(
    function (db, c, criteria, update, options, callback) {
      db.collection(c).insert(docs, function(err, result) {});
    },    // the "real" function
    null, // selection criteria (inadequate here)
    docs, // update data
    null, // options
    null  // callback function
  );
}
/* No more callback needed for the insert function */
mongo.insert ({"name": "doc4"})