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

pgmongo

v0.1.0

Published

implements the Mongo wire protocol and adapts queries to use Postgres jsonb.

Downloads

6

Readme

What is pgmongo?

  • Drop-in replacement Applications should not need code changes because pgmongo imitates a MongoDB server.
  • Stateless proxy pgmongo converts all queries and proxies to a Posgres database.
  • JSON Support for regular JSON data is better than full BSON since jsonb does not have all the advanced data types.

This implements the MongoDB wire protocol and adapts queries to work with a PostgreSQL database using jsonb fields. I've tested it with Keystone.js and it seemed to work reasonably well.

Getting Started

pgmongo requires node 8 or newer and Postgres 9.4+. Then run the following.

npm install -g pgmongo
pgmongo

This will start a mongo-like server on port 27017. If you already have mongo running on your machine you can start it on a different port with the following.

pgmongo localhost 27018

Supported Features

  • listing/creating/dropping collections
  • find (including sorting, skip and offset)
  • count, distinct
  • update (including support for upserting)
  • insert (including batch insertion)
  • deletion
  • creating and listing basic indexes
  • most custom parameters like $gt, $exists, $regex, $push, $set, $unset, etc. See this repo for the full list
  • admin commands (returns mostly stubbed/fake data)

Current status

It's not production ready yet, but definitely working enough to play around with or use in basic apps.
Currently passes 190 of the 916 core mongo jstests.

Example Query Conversions

db.createCollection('users')  ->  CREATE TABLE IF NOT EXISTS "users" (data jsonb)
db.users.find({ lastLogin: { $lte: '2016' } })  ->  SELECT data FROM "users" WHERE data->>'lastLogin'<='2016'
db.users.update({}, { $set: { active: true } })  ->  UPDATE "users" SET data = jsonb_set(data,'{active}','true'::jsonb)
db.users.find({}, { firstName: 1 } )  ->  SELECT jsonb_build_object('firstName', data->'firstName', '_id', data->'_id') as data FROM "users"
db.blogs.insert({ title: 'first post', comments: [] })  ->  INSERT INTO "blogs" VALUES ('{"_id":"5b45b641eb4bd93896d57888","title":"first post","comments":[]}'::jsonb)
db.blogs.remove({ 'state.trash': true })  ->  DELETE FROM "blogs" WHERE data->'state'->'trash'='true'::jsonb

Missing Features / Roadmap (ordered by priority)

Note: contributions/PRs are very much welcome.

  • Support for findandmodify
  • Better for queries matching array elements
  • Preserve BSON (Dates, ObjectIDs, other than _id)
  • Cursors (currently all data is returned in first result)
  • Better Indexes support (not sure if compound indexes are possible)
  • min and max
  • Support numeric object keys (currently numbers are assumed to be an array index)
  • Capped collections
  • geo support
  • explain queries
  • aggregation framework/map reduce queries

Likely Cannot support

  • NaN and Infinity
  • Preserve the initial order of object keys
  • $eval and $where

Resources

Want to contribute?

Anyone can help make this project better. Feel free to open an issue to discuss what you want to work on.

Related Projects

Mongres, mongolike, plv8, ToroDB