# MongoDB Docker Quick Start

Updated: 4/16/2021, 7:48:09 PM
Created: 4/16/2021, 7:48:09 PM
Last Updated By: Mike Wright
Read Time: 7 minute(s)

# Docker Quick Start

# jBASE MongoDB jEDI

# Quick start with Docker containers

If you wish to quickly see the MongoDB jEDI working, you can pull our sample Docker image with MongoDB already built.

docker pull mongo
docker run -it mongo:latest
new window (mongo is running in foreground in the other window)
docker container list                   - get the name of the mongo container
docker inspect <mongocontainername>     - get the ip address
docker pull zumasys/jbase_mongo
docker run -it zumasys/jbase_mongo /bin/bash
jb JBASEADM
jed MD mongo.config   (lower case!!)
# Change line 2 to be the IP address of the mongo container
create-file test.mongo type=mongo
make-demo-file 1000 test.mongo
>Answer Yes
Your file is now in mongo.
# to see it, open a new window:
docker exec -it <mongocontainername> /bin/bash
mongo
show dbs  (You should see JBASEADM)
use JBASEADM
show tables (You should see your tables )
db.test.mongo.find()  (This should show your table)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

The jabba code in the above example has been modified to pull the IP address from the mongo.config item. See below about issues with builtin options

# Build it yourself

# Requirements

  • Linux (Centos 7, RedHat 7/8)
  • jBASE 5.8.0 or later
  • MongoDB installed and listening on port 27017.

# MongoDB Driver install

We need to install the latest mongo-c-driver from the git repository:

https://github.com/mongodb/mongo-c-driver.git
1

There are two ways to retrieve this.

1. git clone https://github.com/mongodb/mongo-c-driver.git
2. curl -O https://github.com/mongodb/mongo-c-driver/archive/r1.16.zip
1
2

You now must install dependencies to make this driver. This driver uses cmake3 which is not available in the default Redhat/Centos installs. Instead the default cmake is cmake2.

On Centos/Redhat you must install the epel package and then you can install cmake3, although this will normally be installed as a dependency by the jBASE 5.8 installer.
Debian must make cmake be the cmake3 version.
On Centos cmake is cmake2 and will NOT work.

yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum install -y cmake3
yum install -y make
yum install -y openssl-devel cyrus-sasl-devel
1
2
3
4

Now, cd into the mongo-c-driver repository.

# from the mongo-c-driver directory
mkdir cmake-build
cd cmake-build
cmake3 -DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF ..
make install
1
2
3
4
5

You should see a long build process. When this is done the driver is built and the lib files are now in /usr/local/lib64 and the headers are in /usr/local/include.

You can now compile the jabba driver. Go into an account and create a directory to do this work. In that directory add the supplied mongo jabba code.

Right now the IP address of the mongo server is not working if you try to pass it. Find the IP address of your mongo server and just manually put it in the code, although a mongo server instance installed locally will be found.

You then compile as follows:

cd into the directory with the jabba code.

jcompile -I/usr/local/include/libmongoc-1.0 -I/usr/local/include/libbson-1.0 -L/usr/local/lib -lmongoc-1.0 jediMongo.jabba -lmongoc-1.0 -lbson-1.0 -o libjedimongo.so
cp lib* ../lib   /* or wherever your default lib directory is */
1
2
sh SandBox ~ -->create-file demofile type=mongo
Notice: Assuming options 'collection=demofile]D database=zumasys write=named'
[ 417 ] File demofile]D created , type = OBJECT
Notice: Assuming options 'collection=demofile database=zumasys write=named'
[ 417 ] File demofile created , type = OBJECT
1
2
3
4
5

Create some content in the demofile

jsh support ~ -->CT demofile 1

    1
001 Attribute 1
002 Attribute 2
003 Attribute 3
004 Attribute 4
005 Attribute 5
1
2
3
4
5
6
7
8

Switch to Mongo:

> show dbs
admin    0.000GB
config   0.000GB
local    0.000GB
support  0.000GB
> use support
switched to db support
> show collections
demofile
demofile]D
> db.demofile.find()
{ "_id" : "1", "_type" : "named", "_attr00001" : "Attribute 1", "_attr00002" : "Attribute 2", "_attr00003" : "Attribute 3", "_attr00004" : "Attribute 4", "_attr00005" : "Attribute 5" }
> 
1
2
3
4
5
6
7
8
9
10
11
12
13

# Note #1

When you create a file, it won't show in Mongo until at least 1 item has been written.
Hence initially only the dictionary section is shown, as the create-file writes a Q pointer into the dictionary.

CREATE-FILE has more options available for "type=mongo" where you can define the database and the collection:

sh support ~ -->create-file GREG type=mongo database=production collection=makedemofile
Notice: Assuming options 'write=named'
[ 417 ] File GREG]D created , type = OBJECT
Notice: Assuming options 'write=named'
[ 417 ] File GREG created , type = OBJECT
jsh support ~ -->make-demo-file 1000 GREG (C

1,000 records created.
jsh support ~ -->COUNT GREG

 1000 Records counted

sh support ~ -->cat GREG
JBC__DYN class=mongo options={"database":"production","collection":"makedemofile","read":"mv","write":"named"}
sh support ~ -->cat GREG]D
JBC__DYN class=mongo options={"database":"production","collection":"makedemofile]D","read":"mv","write":"named"}
sh support ~ -->
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
> show dbs
admin       0.000GB
config      0.000GB
local       0.000GB
production  0.000GB
support     0.000GB
> use production
switched to db production
> show dbs
admin       0.000GB
config      0.000GB
local       0.000GB
production  0.000GB
support     0.000GB
> show collections
makedemofile
makedemofile]D
>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

We can write objects to both a jBASE file and a MongoDB file:

sh support ~ -->create-file mike-jd
[ 417 ] File mike-jd]D created , type = JD
[ 417 ] File mike-jd created , type = JD
sh support ~ -->create-file mike-mongo type=mongo
Notice: Assuming options 'collection=mike_2dmongo]D database=support write=named'
[ 417 ] File mike-mongo]D created , type = OBJECT
Notice: Assuming options 'collection=mike_2dmongo database=support write=named'
[ 417 ] File mike-mongo created , type = OBJECT


sh support ~ -->ct PGM mike.jabba

    mike.jabba
001     open "mike-jd" to mike.jd else stop 201,"mike-jd"
002     open "mike-mongo" to mike.mongo else stop 201,"mike-mongo"
003
004     obj = new object
005     obj->name = "Greg"
006     obj->ishehandsome = @true
007     obj->age = 42
008     write obj on mike.jd,"mike"
009     write obj on mike.mongo,"mike"
010


sh support ~ -->ct mike-jd

    mike
001 {"name":"Greg","ishehandsome":true,"age":42}


sh support ~ -->ct mike-mongo

    mike
001 {"_id":"mike","name":"Greg","ishehandsome":true,"age":42,"_type":"object"}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

We can also use a simple jabba program to re-read the objects and perform verification:

    mike-verify.jabba
001     filename = "mike-jd" ; gosub 100
002     filename = "mike-mongo" ; gosub 100
003
004     stop
005
006 100       *
007
008     open filename to filevar else stop 201,filename
009
010     ctr = 0
011     select filevar
012
013     loop while readnext id do
014         read rec from filevar,id else debug
015         if not(rec->$isobject()) then print "Error. Non object returned" ; debug
016         if rec->age ne 42 then print "Error. The 'age' property is not 42" ; debug
017         ctr++
018     repeat
019
020     crt ctr:" items found in file " : filename:", all of them objects"
021
022     return
023

sh support ~ -->mike-verify
1 items found in file mike-jd, all of them objects
1 items found in file mike-mongo, all of them objects

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

Read a MongoDB document (i.e. one that wasn’t put there by jBASE).

We will use a start-up document like this:

create-file STARTUP type=mongo database=local collection=startup_log


jed STARTUP *

File STARTUP , Record 'vancouver.jinternal.com-1520003836469' (JSON Object)                                                                                    Insert      17:33:44
Command->
0001 {
0002     "_id":"vancouver.jinternal.com-1520003836469",
0003     "hostname":"vancouver.jinternal.com",
0004     "startTime":{
0005         "$date":1520003836000
0006
0007     },
0008     "startTimeLocal":"Fri Mar  2 15:17:16.469",
0009     "cmdLine":{
0010         "config":"\/etc\/mongod.conf",
0011         "net":{
0012             "bindIp":"127.0.0.1",
0013             "port":27017
0014
0015         },
0016         "processManagement":{
0017             "fork":true,
0018             "pidFilePath":"\/var\/run\/mongodb\/mongod.pid",
0019             "timeZoneInfo":"\/usr\/share\/zoneinfo"
0020
0021         },
0022         "storage":{
0023             "dbPath":"\/var\/lib\/mongo",
0024             "journal":{
0025                 "enabled":true
0026
0027             }
0028
0029         },
0030         "systemLog":{
0031             "destination":"file",
0032             "logAppend":true,
0033             "path":"\/var\/log\/mongodb\/mongod.log"
0034
0035         }
0036
0037     },
0038     "pid":59342,
0039     "buildinfo":{
0040         "version":"3.6.3",
0041         "gitVersion":"9586e557d54ef70f9ca4b43c26892cd55257e1a5",
0042         "modules":[
0043
0044         ],
0045         "allocator":"tcmalloc",
0046         "javascriptEngine":"mozjs",
0047         "sysInfo":"deprecated",
0048         "versionArray":[
0049             3,
0050             6,
0051             3,
0052             0

.. snip ..

0069
0070         },

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65

We can access all the startup log records with a simple piece of jabbascript to read the items from the “STARTUP” file we just created:

sh support ~ -->CT PGM startup.jabba

    startup.jabba
001     open "STARTUP" to filevar else stop 201,"STARTUP"
002
003     select filevar
004     loop while readnext id do
005         read obj from filevar,id else debug
006         idate = obj->startTime->$date   ;* This is the UTC date in milliseconds
007         idate = int(idate/1000)         ;* Convert to seconds
008         crt id : " " :
009         crt oconv(idate,"U0ff1" : @vm : "D4"):" ":    ;* Display the date
010         crt oconv(idate,"U0ff0" : @vm : "MTS")        ;* Display the time
011     repeat


sh support ~ -->startup | more

.. snip ..

vancouver.jinternal.com-1616519064750 23 MAR 2021 17:04:24
vancouver.jinternal.com-1616519168953 23 MAR 2021 17:06:08
vancouver.jinternal.com-1616519872365 23 MAR 2021 17:17:52
vancouver.jinternal.com-1616520732711 23 MAR 2021 17:32:12
vancouver.jinternal.com-1616576014269 24 MAR 2021 08:53:34
sh support ~ -->
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

# Useful URLS

MongoDB documentation

MongoDB shell

MongoDB shell tutorial

Full documentation on the MongoDB C Driver

Mongo API documentation

# Note #2

Upcoming Feature Development:

  • sub-value support
  • improved transformation speed

Back to MongoDB jEDI