# Postgres and Node - Hands on using Postgres as a Document Store with MassiveJS

DevFeed: [Postgres and Node - Hands on using Postgres as a Document Store with MassiveJS](<https://devfeed.tech/articles/postgres-and-node-hands-on-using-postgres-as-a-document-store-with-massivejs-41182.md>)

Original publisher: [Read original article](<https://www.craigkerstiens.com/2015/12/08/Postgres-and-Node-Hands-on-using-Postgres-as-a-Document-Store-with-MassiveJS/>)

Author: Map

Published: 2015-12-08T20:55:56Z

Content type: tutorial

Language: en

Sources: [Craig Kerstiens](<https://devfeed.tech/sources/craig-kerstiens.md>)

Topics: [Database](<https://devfeed.tech/topics/database.md>), [JSON](<https://devfeed.tech/topics/json.md>), [NoSQL](<https://devfeed.tech/topics/nosql.md>), [Library](<https://devfeed.tech/topics/library.md>)

Tags: [database](<https://devfeed.tech/tags/database.md>), [json](<https://devfeed.tech/tags/json.md>), [jsonb](<https://devfeed.tech/tags/jsonb.md>), [library](<https://devfeed.tech/tags/library.md>), [node](<https://devfeed.tech/tags/node.md>), [nosql](<https://devfeed.tech/tags/nosql.md>), [postgres](<https://devfeed.tech/tags/postgres.md>), [postgresql](<https://devfeed.tech/tags/postgresql.md>)

## AI overview

A hands-on tutorial showing how to use Postgres as a document store with JSONB and MassiveJS. It reviews Postgres support for hstore, JSON, JSONB, and indexing, then demonstrates creating a table, loading JSON data, and saving documents.

## Source excerpt

JSONB in Postgres is absolutely awesome, but it's taken a little while for libraries to come around to make it as useful as would be ideal. For those not following along with Postgres lately, here's the quick catchup for it as a NoSQL database. In Postgres 8.3 over 5 years ago Postgres received hstore a key/value store directly in Postgres. It's big limitation was it was only for text In the years after it got GIN and GiST indexes to make queries over hstore extremely fast indexing the entire collection In Postgres 9.2 we got JSON... sort of. Really this way only text validation, but allowed us to create some functional indexes which were still nice. In Postgres 9.4 we got JSONB - the B stands for Better according to @leinweber. Essentially this is a full binary JSON on disk, which can perform as fast as other NoSQL databases using JSON. This is all great, but when it comes to using JSON you need a library that plays well here. As you might have guessed it from my previous post this is where MassiveJS comes in. Most ORMs take a more legacy approach to how they work with the database, in contrast the other side of the world believes in document only storage way is the future. In contrast Postgres believes there is a time and place for everything, just like Massive, except it believes Postgres is the path just as I do. Alright, enough context, let's take a look. Getting all setup First go ahead and create a database, let's call it massive, and then let's connect to it and create our example table: $ createdb massive $ psql massive # create table posts (id serial primary key, body jsonb); Now that we've got our database setup let's seed it with some data. If you want you can simple hop over to the github repo and pull it down then run node load_json.js to load the example data. A quick look at it, given an example.json file we're going to iterate over it. For each record in there, we're going to call saveDoc. Based on our table which has a unique id key and a body jsonb