You are on page 1of 6

PHASE 1 – INSTALLATION

Section I - Installing MongoDB on Virtual/Client PC

A. Open the installer and click next until the end. No need to configure anything.
B. If you’re using a virtual machine, follow through this step.
a. Open MongoDB Folder from where your installation directory. (Default
should be on "C:\Program Files\MongoDB\Server\4.2\bin ")
b. Move (Cut) the mongod.cfg to your Dekstop then open it using notepad.
Change the bindIp from 127.0.0.1 to 0.0.0.0

c. Move the mongod.cfg from Desktop back to the installation directory.


d. Restart Virtual PC.
C. Fill database with tables.
a. > use teacherEnroll; will create a schema names
teacherEnroll
b. > db.createCollection(“Teachers”); will create
collection (table). Do the same for Subjects and Enroll
c. > db.Teachers.insert({TID: 1, Name:”Kyle”, Dept:”CS”});
will insert a teacher on the Teachers Table. Do the same
for Subjects only.
d. Leave the Enroll collection blank as the insertion will
be done by the Java Program.

Section II- Installing MongoDB Driver on Netbeans

A. Open Netbeans and click on the Tools > Plugins on the upper menu.
B. Click on the Available Plugin Tabs and search for NBMongo, then toggle the
checkbox, then click Install

C. Click on the Download tab, then click Add Plugin, then search for the MongoDB Java
Driver JAR file (make sure to toggle JAR files on the Files of Type dropdown box),
then click install.

D. Restart your PC (and your Virtual PC)

PHASE 2- CREATING THE PROGRAM

Section I- Creating the GUI


A. Click File > New Project on the upper menu. Choose Java as Category, then Java
Application as Project, then click Next. Configure the project name, and click Next.
B. Right click on the package, then hover on New, then click JFrame Form.

C. Design a form which will contain 3 Tables and 1 “Assign” Button.

Section II- Creating Functionalities

A. Import the things needed.


a. Import com.mongodb.*;
b. Import javax.swing.table.DefaultTableModel;
B. Declare a connection to mongoDB
a. MongoClient mongoCLient = new MongoClient(new
MongoClientURI(“mongodb://ipAddress:27017”));
C. Create a reference for:
a. The Database
i. DB database = mongoClient.getDB(“teacherEnroll”);
b. The Collections/Tables
i. DBCollection colTeachers =
database.getCollection(“Teachers”);
D. Functions to:
a. Show Teachers from database to tables:
public void showTeachers(){ }
b. Show Subjects from database to tables:
public void showSubjects(){ }
c. Show Enrolled from database to tables:
public void showEnrolled(){ }
d. Assign a subject to a teacher:
public void enrollTeacher() { }
E. Guides:
a. To show values from database to tables:
i. Declare a cursor
DBCursor cursor = colTeachers.find();
ii. Declare table model
DefaultTableModel mdlTeachers = new DefaultTableModel(c,
0); where c is an array that contains table headers.
iii. Iterate through the cursor
while(cursor.hasNext()){
DBObject obj = cursor.next();
double tid = (double)obj.get(“TID”);
mdlTeachers.addRow(new Object[]{(int)tid}); //this
will only show the teacher’s ID on the table. You need
to modify this code to show the Name and the Department.
b. To show selected value on the table, refer to the Exer1 from the midterms.

ps. Since this code is from sir, you can copy the sht out of it.
Good luck

You might also like