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

mongolike

v0.1.3

Published

MongoDB Clone on top of Postgres

Downloads

11

Readme

Mongolike

Mongolike is an experimental MongoDB clone being built on top of PLV8 and Postgres.

Implemented (so far)

  • create_collection()
  • drop_collection()
  • save()
  • find()
  • runCommand() (Map/Reduce)
  • ensureIndex()
  • removeIndex()
  • getIndexes()

Installing

Install PLV8

Visit http://code.google.com/p/plv8js/wiki/PLV8 and follow the build instructions.

Install Mongolike

The Easy Way

The easy way to install is to use node.js.

$ npm install -g mongolike
$ mongolike-install -d yourdb

The Slight Less Easy Way

$ psql yourdb <sql/*.sql

Running Tests

Mongolike includes a test suite and a test runner.

$ test/test_runner.js -d yourdb

Additional tests can be added to test/tests.sql.

Using

All commands must be prefixed by SELECT, and are modified slightly to work in the Postgres environment.

create_collection(collection)

Create a collection.

Example:

SELECT create_collection('test');

drop_collection(collection)

Drop a collection.

Example:

SELECT drop_collection('test');

save(collection, object)

Save an object into a collection.

Example:

SELECT save('test', '{ "foo": "bar" }');

find(collection /*, terms, limit, skip */)

Find an object, with optional terms, limit, and skip.

Example:

SELECT find('test', '{ "type": { "$in": [ "food", "snacks" ] } }');

runCommand(command)

Run a command on the Database. Currently only mapReduce is supported.

NOTE The JSON object cannot have carriage returns, the example below does for readability.

Example:

SELECT runCommand('{
  "map": "function MapCode() {
    emit(this.Country, {
      \"data\": [
        {
          \"city\": this.City, 
          \"lat\":  this.Latitude, 
          \"lon\":  this.Longitude
        }
      ]
    });
  }",
  "reduce": "function ReduceCode(key, values) {
    var reduced = {
      \"data\": [ ]
    };
    for (var i in values) {
      var inter = values[i];
      for (var j in inter.data) {
        reduced.data.push(inter.data[j]);
      }
    }
    return reduced;
  }",
  "mapreduce": "cities",
  "finalize": "function Finalize(key, reduced) {
    if (reduced.data.length == 1) {
      return {
        \"message\" : \"This Country contains only 1 City\"
      };
    }

    var min_dist = 999999999999;
    var city1 = { \"name\": \"\" };
    var city2 = { \"name\": \"\" };
    var c1;
    var c2;
    var d;

    for (var i in reduced.data) {
      for (var j in reduced.data) {
        if (i >= j) continue;
        c1 = reduced.data[i];
        c2 = reduced.data[j];
        d = Math.sqrt((c1.lat-c2.lat)*(c1.lat-c2.lat)+(c1.lon-c2.lon)*(c1.lon-c2.lon));

        if (d < min_dist && d > 0) {
          min_dist = d;
          city1 = c1;
          city2 = c2;
        }
      }
    }
    return {
      \"city1\": city1.city,
      \"city2\": city2.city,
      \"dist\": min_dist
    };
  }" }');

ensureIndex(collection, terms /*, type */)

Creates a new index on a collection.

Example:

SELECT ensureIndex('test', '{ "foo", "bar" }', '{ "unique": true }');

removeIndex(collection, name)

Removes an index from a collection by name.

Example:

SELECT removeIndex('test', 'idx_col_woo_foo');

removeIndex(collection, terms)

Removes an index from a collection by terms.

NOTE in order to remove an index with terms you MUST cast the query due to how Postgres handles JSON.

Example:

SELECT removeIndex('test', '{ "foo", "bar" }'::json);

getIndexes(collection)

Retrieves all indexes for a given collection.

Example:

SELECT getIndexes('test');

Importing the Data

I have included a modest amount of data for testing and benchmarking, both for Postgres and for MongoDB (1,706,873 rows).

Importing into Postgres:

$ psql yourdb < data/cities.sql

This will create the collection and save() all of the data.

Importing into MongoDB

$ mongoimport --collection cities --type csv --headerline --file data/cities.csv --db yourdb

Follow along at http://legitimatesounding.com/blog/