Using MySQL to save and query JSON documents

Installation

mysql> INSTALL PLUGIN mysqlx SONAME 'mysqlx.so';
mysql> SHOW PLUGINS;

The Document Store

MySQL Shell

mysqlsh -u username your_database
mysql-js> db = session.getSchema("your_database");
<Schema:your_database>
mysql-js> db.createCollection("YourCollection");
<Collection:YourCollection>
mysql-js> db.YourCollection.add({_id: "oba", name: "OneBitAhead"})
Query OK, 1 item affected
mysql-js> db.YourCollection.find("_id = 'oba'")
[{_id: "oba", name: "OneBitAhead"}]
1 document in set

Combining both the Document and the SQL world

mysql-js> db.TableA.insert("id", "name") values ("oba", "OneBitAhead");mysql-js> db.TableA.select(["id", "name"]).where("id = 'oba'");
1 row in set

That’s it for now

--

--

--

The tech staff of OneBitAhead GmbH, putting the web stack to work. Here to discuss daily bits & bytes. #javascript #nodejs #webcomponents #rdbms #php

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
OneBitAhead

OneBitAhead

The tech staff of OneBitAhead GmbH, putting the web stack to work. Here to discuss daily bits & bytes. #javascript #nodejs #webcomponents #rdbms #php

More from Medium

How to reduce NodeJS Docker Image Size?

Dockerized React Nginx Deploy: A simple starter template.

CI/CD using GitHub Actions, Build/Push Docker Image to Docker Hub

How to Dockerize a NodeJs Application 🐳

nodejs docker app