• Stars
    star
    386
  • Rank 111,213 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 12 years ago
  • Updated about 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A proof of concept MongoDB clone built on Postgres

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 Slightly Less Easy Way

$ for file in sql/*.sql; do psql yourdb < $file; done

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/

More Repositories

1

date-utils

Date Pollyfills for Node.js and Browser
JavaScript
373
star
2

cromagjs

Advanced Date and Time, Without the Monkeys
JavaScript
68
star
3

bricks

bricks web application platform
JavaScript
54
star
4

Dumbar

A smrt, no, smart, ok, no dumb smartbar for Ollama
JavaScript
51
star
5

equinox

Testing for Postgres
JavaScript
43
star
6

node-judy

Judy Arrays Implemented in Node.js
C
36
star
7

servitude

JavaScript and CSS Sugar Middleware
JavaScript
35
star
8

EventDuino

Evented Arduino and Node.js
JavaScript
24
star
9

EurorackClock

A clock module for Eurorack systems
C++
21
star
10

judyarray

Automatically exported from code.google.com/p/judyarray
C
17
star
11

bookmarkdown

An Experimental Book Creation Platform
JavaScript
12
star
12

SynthDevKit

Utilities for development of software and hardware synthesizers
C++
10
star
13

ProtoTools

Prototyping tools for VCVRack
C++
9
star
14

db-engine

database abstraction engine, with index and backing store support
JavaScript
9
star
15

plv8-modules

CommonJS for PLV8
JavaScript
8
star
16

nodepdx-bricksjs

Building Applications with Bricks.js
JavaScript
6
star
17

judy-revisited

Judy Arrays for Node.js
JavaScript
6
star
18

Instruments

sample based instruments for VCV Rack
Objective-C
5
star
19

bricks-rewrite

bricks.js rewrite module
JavaScript
5
star
20

memstore

In-memory key/value store
JavaScript
5
star
21

mock-request-response

mock request and response objects for smarter testing
JavaScript
4
star
22

pebble-weather-watchface

Pebble Watch App - Pebble SDK 2.0
C
3
star
23

bricks-analytics

analytics and status package for bricks.js
JavaScript
3
star
24

vcv-httpserver

An HTTP Server for VCV Rack
C++
3
star
25

global

Global Pattern for Node.js
JavaScript
3
star
26

plv8-geo

Geo Tools for PLV8
PLpgSQL
3
star
27

100-lines-or-less-js

What's the coolest ArcGIS JavaScript app you can write in 100 lines or less?
3
star
28

arptest

A Rack Plugin Test platform - module testing for VCVRack
C++
3
star
29

memoryam

in-memory tableam implementation for postgres
C++
3
star
30

cdb

a proof of concept clustered database engine
C++
2
star
31

Footprints

Logging and OpenTelemetry
JavaScript
2
star
32

http-db

http based database
JavaScript
2
star
33

json

JSON Formatter - Makes JSON Pretty
JavaScript
2
star
34

pljs

quick proof of concept
C
2
star
35

temperature

Node and Arduino based temperature monitor
JavaScript
2
star
36

bricks-compress

output compression using gzip for bricks.js
JavaScript
2
star
37

duk_modules

Node.js like module system for DukLuv
JavaScript
2
star
38

mf2

Microformat 2 Parser for the Command-Line
JavaScript
2
star
39

recipe-scrapers

Scrape recipes into h-recipe format
JavaScript
2
star
40

4dlcd

Node.js implementation of the 4D SGC/Picasso LCD Controllers
JavaScript
2
star
41

byod-store

Build Your Own Database - Storage Module
JavaScript
1
star
42

csv-parser-generator

A CSV Parser Generator, fast, simple
JavaScript
1
star
43

QuickJS

Local copy of QuickJS with some modifications
C
1
star
44

index-judy

A C library for easy exposure to a Judy Array index.
C
1
star
45

jsonschema-markdown

Creates Markdown from JSON-Schema
JavaScript
1
star
46

JSONvJSONB

PLpgSQL
1
star
47

terraformer-geostore-leveldb

A Geostore backend for Terraformer utilizing LevelDB
JavaScript
1
star
48

silly-to-json

SillyMUD world to arbitrary JSON converter
C
1
star
49

dogeface

A Dogecoin watch face for Pebble watches
C
1
star
50

pdxpug

C
1
star
51

static-httpd

A fast static http server written in C
C
1
star
52

rack-components

Components for VCV Rack
C++
1
star
53

weather-notification

weather notification widget using dark sky and pushover
JavaScript
1
star
54

Counties-WKT

Well Known Text US Counties (fairly high resolution)
1
star
55

hapi-auth-jwt

JWT Authentication Plugin for HAPI
JavaScript
1
star
56

quickstart-js

An ArcGIS Javscript library and samples to help you start building web mapping applications quickly.
JavaScript
1
star
57

seapug

1
star
58

mongolike-client

A node.js client library for MongoLike
CSS
1
star
59

pllisp

C
1
star