A proof of concept MongoDB clone built on Postgres
github.com
github.com
For those who aren't aware, Postgres currently lacks support for doing updates to JSON fields via SQL[1]. For many this isn't a problem, but I'd imagine that people expecting a MongoDB clone would need it.
[1] But even though you can individually address the various fields within the JSON document, you can’t update a single field. Well, actually you can, but by extracting the entire JSON document out, appending the new values and writing it back, letting the JSON parser sort out the duplicates. https://blog.compose.io/is-postgresql-your-next-json-databas...
http://www.postgresql.org/message-id/flat/54E00D1F.9060101@d...
If we can address fields with operators (->, ->>, etc.) then why can't those operators modify, too? It works for everything else, after all. It's fairly counter-intuitive from a dev perspective.
That, and PLV8 still doesn't support JSONB. With JSONB being so much more efficient, faster, and so on, not being able to interact with it using the most logical procedural language is an EPIC oversight.
It certainly doesn't work for "everything else". You can update individual "parts" of arrays and record types, that's it. And those exception are hard-coded, so someone would either have to hard-code similar exceptions for JSON values (ugly, inflexible, generally a bad idea) or generalize support for custom operators on the left-hand side of assignments in UPDATE. All this while trying to push out a release which was already late by months.
You can call everything an oversight, but with very limited resources available and the need to cut a release at some point, this is far from the truth in this case.
this is non-optimal, but currently the only method available.
So does CouchDB: https://cloudant.com/blog/couchdb-and-mongodb-let-our-query-...
https://github.com/zumero/Elmo
In F#. Not even remotely close to usable or production-ready.
The approach here is somewhat different, as this implementation is built on SQLite, which it treats as a simple key-value storage layer.
Check out ToroDB (github.com/torodb/torodb). It is a Mongo implementation based on PostgreSQL that transforms JSON documents into relational tables. This has many advantages like significant storage reduction, less I/O required and it allows for updates (a concern raised on some comments below). Please check it out! :)
But then I saw that this project started two years ago, and the last commit was a year ago.
Investigating standalone alternatives therefore seems like a good thing, even for projects starting today.
Do you have a source on this? I can't find anything at the moment but it sounds familiar.
So far, the basic crud stuff works and there's a python driver with decent test coverage. Progress is slow, but it's fun!
Does it use HSTORE?
Nice project!
"As of version 9.4, PostgreSQL benchmarks faster than MongoDB for both inserting and querying JSON data." :P
The blog posts go into more details: http://legitimatesounding.com/blog/building_a_mongodb_clone_... and http://legitimatesounding.com/blog/building_a_mongodb_clone_...
Which leads to a question for the OP: does this work with mongoose.js?
in the end, i just wrote my own database system, with a query language that could act as an intermediary from multiple sources (SQL, mongo, etc).
but, this stuff is mostly just for fun, my day job keeps me plenty busy.
http://www.postgresql.org/docs/devel/static/logicaldecoding.... for the (somewhat low level) description of the feature. You'd have to write an output plugin that formats the output as json, but that should be pretty easy.
Disclaimer: I'm the author of the feature ;)
Certainly, logical decoding provides the necessary infrastructure to implement it (and also normal tailable cursors): thank you Andres, really nice work! :) But some work is also needed to transform the representation you are using in PostgreSQL into MongoDB's oplog entries.
This is definitely what we are using in ToroDB to emulate it (currently, under development).
What happened to separating the data access layer from the business logic layer? Oh yeah, "good architectural practices are so JEE ..." /s