NoSQL on IBM i
db2nosql – A command line shell to create and query JSON data using Mongo commands. To start the command line processor, use QSHELL and run /QIBM/ProdData/OS/SQLLIB/bin/db2nosql.
The
command runs through JDBC driver so ensure JRE is set in the PATH and CLASSPATH
has the JDBC driver. Once command line processor shows “NoSQL” type enable (true)
to set up the database artifacts.
SQL Terms/Concepts
|
MongoDB Terms/Concepts
|
database
|
database
|
table
|
collection
|
row
|
document
or BSON document
|
column
|
field
|
index
|
index
|
table
joins
|
$lookup,
embedded documents
|
primary
key
|
primary
key
|
Specify
any unique column or
Column
combination as primary key.
|
In
MongoDB, the primary key is
automatically set to the _id field. |
aggregation
(e.g. group by)
|
aggregation
pipeline
|
Database
and Collections
Create a database with ‘use dbname’
- use petshop E.g. Below screenshot show how a new DB PETSHOP is created. With
use if a database exists with that name it will be switched else a new database
will be created.
Create collections - Collections in MongoDB is analogous to a table of an RDBMS.
CRUD Operations -
db.collection.insert({ }) - Inserts a
document or documents into a collection.
db.collection.find({ }) - Returns all the document or documents in a collection.
db.collection.find().limit(1) - Returns just one document in a collection.
db.collection.update -
db.mammals.update({"name" : "Star Nosed Mole"}, {"name" : "start nosed mole"})