Example usage for com.mongodb MongoClient MongoClient

List of usage examples for com.mongodb MongoClient MongoClient

Introduction

In this page you can find the example usage for com.mongodb MongoClient MongoClient.

Prototype

public MongoClient(final MongoClientURI uri, final MongoDriverInformation mongoDriverInformation) 

Source Link

Document

Creates a Mongo described by a URI.

Usage

From source file:NewJFrame.java

@Override
public void actionPerformed(ActionEvent ae) {
    // TODO Auto-generated method stub
    add(jLabel5);/*  w  w  w.ja  va  2  s  . c  om*/
    String user = jTextField1.getText().toString();
    @SuppressWarnings("deprecation")
    String pass = jPassword1.getText().toString();
    jLabel5.setText("");

    if (ae.getSource() == jButton1) {
        if ((String) jComboBox1.getSelectedItem() == "Admin") {
            if (user.equals("admin") && pass.equals("admin123")) {
                this.setVisible(false);
                new Admin().setVisible(true);
            } else {
                jLabel5.setFont(new java.awt.Font("SansSerif", 3, 14)); // NOI18N
                jLabel5.setForeground(new java.awt.Color(25, 25, 112));
                jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
                jLabel5.setText("Login Not Successful ");
                jTextField1.setText("");
                jPassword1.setText("");
                jLabel5.setBounds(120, 245, 170, 50);
            }
        } else if ((String) jComboBox1.getSelectedItem() == "Trainer") {
            try {
                MongoClient mongo = new MongoClient("localhost", 27017);
                DB db = mongo.getDB("Gym");
                DBCollection Gym_Collection = db.getCollection("trainer");
                BasicDBObject fields = new BasicDBObject("Username", user).append("Password", pass);
                String s;
                DBCursor cursor1 = Gym_Collection.find(fields);
                if (cursor1.hasNext()) {
                    cursor1.next();
                    s = cursor1.curr().get("First_Name").toString();
                    new Receptionist(s);
                    this.setVisible(false);
                    new Receptionist().setVisible(true);
                } else {
                    jLabel5.setFont(new java.awt.Font("SansSerif", 3, 14)); // NOI18N
                    jLabel5.setForeground(new java.awt.Color(25, 25, 112));
                    jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
                    jLabel5.setText("Login Not Successful ");
                    jTextField1.setText("");
                    jPassword1.setText("");
                    jLabel5.setBounds(120, 245, 170, 50);
                }
            } catch (UnknownHostException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }
    }
}

From source file:CramMd5CredentialsExample.java

License:Apache License

public static void main(String[] args) throws UnknownHostException, InterruptedException {
    String server = args[0];/* w  w  w.  j  ava  2 s  .  c om*/
    String user = args[1];
    String pwd = args[2];
    String db = args[3];
    MongoClient mongo = new MongoClient(
            new MongoClientAuthority(new ServerAddress(server),
                    new MongoClientCredentials(user, pwd.toCharArray(),
                            MongoClientCredentials.CRAM_MD5_MECHANISM, db)),
            new MongoClientOptions.Builder().socketKeepAlive(true).socketTimeout(30000).build());
    DB testDB = mongo.getDB(db);
    System.out.println("Find     one: " + testDB.getCollection("test").findOne());
    System.out.println("Count: " + testDB.getCollection("test").count());
    WriteResult writeResult = testDB.getCollection("test").insert(new BasicDBObject());
    System.out.println("Write result: " + writeResult);

    System.out.println();

    System.out.println("Count: " + testDB.getCollection("test").count());

}

From source file:RestrictedService.java

License:Open Source License

public void init() throws ServletException {
    if (!gateInited) {
        try {/*  w  ww.  ja v  a2s. co m*/
            // GATE home is setted, so it can be used by SAGA.
            ServletContext ctx = getServletContext();
            File gateHome = new File(ctx.getRealPath("/WEB-INF"));
            Gate.setGateHome(gateHome);
            // GATE user configuration file is setted. 
            Gate.setUserConfigFile(new File(gateHome, "user-gate.xml"));
            //GATE is initialized as non visible.
            Gate.init();
            // We load the plugins that are going to be used by the SAGA modules.
            // Load ANNIE.
            Gate.getCreoleRegister().registerDirectories(ctx.getResource("/WEB-INF/plugins/ANNIE"));
            // Load processingResources (from SAGA)
            Gate.getCreoleRegister()
                    .registerDirectories(ctx.getResource("/WEB-INF/plugins/processingResources"));
            // Load webProcessingResources (from SAGA)
            Gate.getCreoleRegister()
                    .registerDirectories(ctx.getResource("/WEB-INF/plugins/webProcessingResources"));
            // Now we create the sentiment analysis modules that are going to be provided by the service.
            // English financial module.
            ArrayList<URL> dictionaries = new ArrayList<URL>();
            dictionaries.add((new RestrictedService()).getClass().getResource("/LoughranMcDonald/lists.def"));
            modules.put("enFinancial",
                    new DictionaryBasedSentimentAnalyzer("SAGA - Sentiment Analyzer", dictionaries));
            // English financial + emoticon module.
            ArrayList<URL> dictionaries2 = new ArrayList<URL>();
            dictionaries2.add((new RestrictedService()).getClass().getResource("/LoughranMcDonald/lists.def"));
            dictionaries2.add((new RestrictedService()).getClass()
                    .getResource("/resources/gazetteer/emoticon/lists.def"));
            modules.put("enFinancialEmoticon",
                    new DictionaryBasedSentimentAnalyzer("SAGA - Sentiment Analyzer", dictionaries2));
            // Mongo login
            String user = "";
            String password = "";
            MongoCredential credential = MongoCredential.createMongoCRCredential(user, "RestrictedDictionaries",
                    password.toCharArray());
            MongoClient mongoClient = new MongoClient(new ServerAddress("localhost"),
                    Arrays.asList(credential));
            db = mongoClient.getDB("RestrictedDictionaries");

            gateInited = true;

        } catch (Exception ex) {
            throw new ServletException("Exception initialising GATE", ex);
        }
    }
}

From source file:MongoDBRepo.java

public static MongoDBRepo getInstance() {
    if (MongoDBRepo.instance == null) {
        MongoDBRepo.instance = new MongoDBRepo();
        //            MongoDBRepo.mongoClient = new MongoClient("141.71.5.19", 27017);
        MongoDBRepo.mongoClient = new MongoClient("127.0.0.1", 27017);
        MongoDBRepo.db = mongoClient.getDatabase("workshop");
        date = System.currentTimeMillis() + "";
    }//from   ww  w.  j  a  va  2  s .  c  om
    return MongoDBRepo.instance;
}

From source file:Highscores.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    // TODO add your handling code here:
    try {/* w ww.  j a  va2 s .  c  o  m*/
        String user;
        int count = 1;
        String highscore;
        jTextArea2.append("SR No.\tUSERNAME\tHIGHSCORE\n");
        int high;
        MongoClient mc = new MongoClient("localhost", 27017);
        DB db = mc.getDB("Classic_Hangman");
        System.out.println("Connected to database successfully!!");
        DBCollection coll = db.getCollection("high_score");
        System.out.println("Collection Retrieved");
        DBCursor cursor = coll.find();
        cursor.sort(new BasicDBObject("value", -1));
        while (cursor.hasNext() && count < 4) {
            DBObject result = cursor.next();
            high = ((Number) result.get("value")).intValue();
            highscore = Integer.toString(high);
            user = (String) result.get("_id");
            jTextArea2.append(count + "\t" + user + "\t" + highscore + "\n");
            count++;
        }
    } catch (UnknownHostException ex) {
        Logger.getLogger(Highscores.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:Add_cust.java

@Override
/* Check The code below for insertion of values */
public void actionPerformed(ActionEvent ae) {
    // TODO Auto-generated method stub
    add(jLabel9);//w ww.  ja v  a 2s .c  o  m
    String History = jComboBox3.getSelectedItem().toString();
    if (ae.getSource() == jButton1) {
        try {
            MongoClient mongo = new MongoClient("localhost", 27017);
            DB db = mongo.getDB("Gym");
            DBCollection Gym_Collection = db.getCollection("Customers");
            DBCollection Allot = db.getCollection("Batch"); //Declaration of collection for Batch
            DBCursor cursor = Allot.find();
            float Slots, Morning, Evening, Night;
            cursor.next();
            Slots = Float.parseFloat(cursor.curr().get("Slots").toString());
            Morning = Float.parseFloat(cursor.curr().get("Morning").toString());
            Evening = Float.parseFloat(cursor.curr().get("Evening").toString());
            Night = Float.parseFloat(cursor.curr().get("Night").toString());
            String first_name = jTextField1.getText();
            String last_name = jTextField2.getText();
            float weight = Float.parseFloat(jTextField6.getText().toString());
            float height = Float.parseFloat(jTextField5.getText().toString());
            String address = jTextArea1.getText();
            int age = Integer.parseInt(jComboBox1.getSelectedItem().toString());
            String Subs = jComboBox2.getSelectedItem().toString();

            String Batches = jComboBox5.getSelectedItem().toString();
            String phone_number = jTextField3.getText().toString();
            if (!isAlpha(first_name) || !isAlpha(last_name)) {
                JOptionPane.showMessageDialog(this, "Enter a valid name");
                jTextField1.setText("");
                jTextField2.setText("");
            } else if (weight > 150 || weight < 40) {
                JOptionPane.showMessageDialog(this, "Please add weight between 40 and 150");
                jTextField6.setText("");
            } else if (height > 250 || height < 50) {
                JOptionPane.showMessageDialog(this, "Please add height between 100 and 250");
                jTextField5.setText("");
            } else if (phone_number.length() < 8 || phone_number.length() > 11) {
                JOptionPane.showMessageDialog(this, "Enter a valid Phone no.");
                jTextField3.setText("");
            } else {
                int random_1, random_2, sub_sum = 0, days = 0;
                if (Subs.equals("1 Month")) {
                    sub_sum = 1000;
                    days = 30;
                } else if (Subs.equals("2 Months")) {
                    sub_sum = 1500;
                    days = 60;
                } else if (Subs.equals("3 Months")) {
                    sub_sum = 2250;
                    days = 90;
                } else if (Subs.equals("1 YEAR")) {
                    sub_sum = 6000;
                    days = 360;
                }
                int flag = 0, flag1 = 0, flag2 = 0, flag3 = 0;
                if (Batches.equals("Morning")) {
                    Morning += 1;
                    flag1 = 1;
                } else if (Batches.equals("Evening")) {
                    Evening += 1;
                    flag2 = 1;
                } else if (Batches.equals("Night")) {
                    Night += 1;
                    flag3 = 1;
                }
                if (Morning > Slots || Evening > Slots || Night > Slots) {
                    if (flag1 == 1) {
                        Morning -= 1;
                    } else if (flag2 == 1) {
                        Evening -= 1;
                    } else if (flag3 == 1) {
                        Night -= 1;
                    }
                    flag = 1;
                }
                if (flag == 1) {
                    float temp1, temp2;
                    if (flag1 == 1) {
                        temp1 = Slots - Evening;
                        temp2 = Slots - Night;
                        JOptionPane.showMessageDialog(this, "This time slot slot is full. Evening has " + temp1
                                + " Slots. Night has " + temp2 + " Slots.");
                    } else if (flag2 == 1) {
                        temp1 = Slots - Morning;
                        temp2 = Slots - Night;
                        JOptionPane.showMessageDialog(this, "This time slot slot is full. Morning has " + temp1
                                + " Slots. Night has " + temp2 + " Slots.");
                    } else {
                        temp1 = Slots - Morning;
                        temp2 = Slots - Evening;
                        JOptionPane.showMessageDialog(this, "This time slot slot is full. Morning has " + temp1
                                + " Slots. Evening has " + temp2 + " Slots.");
                    }
                } else {
                    do {
                        random_1 = (int) Math.floor(Math.random() * 360);
                        random_2 = (int) Math.floor(Math.random() * 360);
                    } while (random_1 >= random_2 || days <= random_2);
                    BasicDBObject doc = new BasicDBObject("First_Name", first_name.toLowerCase())
                            .append("Last_Name", last_name.toLowerCase()).append("Phone_Number", phone_number)
                            .append("Age", age).append("Height", height).append("History", History)
                            .append("Subscribe", days).append("Batch", Batches).append("Weight", weight)
                            .append("Attended", random_1).append("Total", random_2).append("Fees", sub_sum)
                            .append("Address", address);
                    Gym_Collection.insert(doc);
                    jTextField1.setText("");
                    jTextField2.setText("");
                    jTextField3.setText("");
                    jTextField5.setText("");
                    jTextField6.setText("");
                    jTextArea1.setText("");

                    BasicDBObject newDocument = new BasicDBObject();
                    newDocument.append("$set", new BasicDBObject().append("Morning", Morning)
                            .append("Evening", Evening).append("Night", Night));

                    BasicDBObject searchQuery = new BasicDBObject().append("Slots", Slots);

                    Allot.update(searchQuery, newDocument);

                    this.setVisible(false);
                    new work(History, first_name.toLowerCase(), last_name.toLowerCase());
                    this.setVisible(false);
                    new work().setVisible(true);
                }
            }
        } catch (UnknownHostException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (NumberFormatException e) {// To validate for data types
            JOptionPane.showMessageDialog(this, "Please Check the Data types");
            jTextField1.setText("");
            jTextField2.setText("");
            jTextField3.setText("");
            jTextField5.setText("");
            jTextField6.setText("");
            jTextArea1.setText("");
        }
    }

    else if (ae.getSource() == jButton2) {
        this.setVisible(false);
        new Receptionist().setVisible(true);
    }
}

From source file:PersistMongo.java

public static void main(String[] args) {
    // conectando ao mongo, como esta sem parametros
    //se conecta ao mongo local por default 
    MongoClient mongoClient = new MongoClient("localhost", 27017);

    // Base de dados
    DB db = (DB) mongoClient.getDB("JavaDB");
    // Tabela //from www .j  a  v a  2s  .  c o m
    DBCollection collection = db.getCollection("colJava");
    // objeto para ser persistido
    BasicDBObject document1 = new BasicDBObject();
    document1.put("id", 1001);
    document1.put("msg", "Persistencia com mongoDB");

    // salvando o documento na base nosql
    collection.insert(document1);
    BasicDBObject document = new BasicDBObject();
    document = new BasicDBObject();
    document.put("id", 1002);
    document.put("msg", "Java + Mongo");

    // salvando o documento na base nosql
    collection.insert(document);
    // objeto que recebe os dados do banco
    DBCursor cursor = collection.find();
    // percorrendo o objeto e mostrando os dados
    while (cursor.hasNext()) {
        System.out.println("Document: " + cursor.next());

    }
    // Passando o documento que sera removido
    collection.remove(document);
    // Passando o documentoque sera atualizado e o documento que entrara em seu lugar 
    collection.update(document, document1);

}

From source file:Add_train.java

@Override
/* Check The code below for insertion of values */
public void actionPerformed(ActionEvent ae) {
    // TODO Auto-generated method stub
    add(jLabel9);//  w w  w .  j  av a 2  s .c o  m
    jLabel9.setText("");
    if (ae.getSource() == jButton1) {
        try {
            MongoClient mongo = new MongoClient("localhost", 27017);
            DB db = mongo.getDB("Gym");
            DBCollection Allot = db.getCollection("Batch_Trainer");
            DBCursor cursor1 = Allot.find();
            DBCollection Gym_Collection = db.getCollection("trainer");
            String first_name = jTextField1.getText();
            String last_name = jTextField2.getText();
            String password = jPassword1.getText().toString();
            String dup = jPassword2.getText().toString();
            String username = jTextField5.getText().toString();
            String address = jTextArea1.getText();

            String Batches = jComboBox5.getSelectedItem().toString();
            float Slots, Morning, Evening, Night;
            cursor1.next();
            Slots = Float.parseFloat(cursor1.curr().get("Slots").toString());
            Morning = Float.parseFloat(cursor1.curr().get("Morning").toString());
            Evening = Float.parseFloat(cursor1.curr().get("Evening").toString());
            Night = Float.parseFloat(cursor1.curr().get("Night").toString());
            int age = Integer.parseInt(jComboBox1.getSelectedItem().toString());
            String phone_number = jTextField3.getText().toString();
            DBCursor cursor = Gym_Collection.find();
            int i = 0;
            while (cursor.hasNext()) {
                cursor.next();
                if (username.equals(cursor.curr().get("Username").toString())) {
                    i = 1;
                }
            }
            if (i == 1) {
                JOptionPane.showMessageDialog(this, "Username has been taken !!!");
                jTextField5.setText("");
            } else if (!isAlpha(first_name) || !isAlpha(last_name)) {
                JOptionPane.showMessageDialog(this, "Enter a valid name");
                jTextField1.setText("");
                jTextField2.setText("");
            } else if (phone_number.length() < 8 || phone_number.length() > 10) {
                JOptionPane.showMessageDialog(this, "Enter a valid Phone no.");
                jTextField3.setText("");
            } else if (!password.equals(dup)) {
                JOptionPane.showMessageDialog(this, "Passwords didn't match");
                jPassword1.setText("");
                jPassword2.setText("");
            } else {

                int flag = 0, flag1 = 0, flag2 = 0, flag3 = 0;
                if (Batches.equals("Morning")) {
                    Morning += 1;
                    flag1 = 1;
                } else if (Batches.equals("Evening")) {
                    Evening += 1;
                    flag2 = 1;
                } else if (Batches.equals("Night")) {
                    Night += 1;
                    flag3 = 1;
                }
                if (Morning > Slots || Evening > Slots || Night > Slots) {
                    if (flag1 == 1) {
                        Morning -= 1;
                    } else if (flag2 == 1) {
                        Evening -= 1;
                    } else if (flag3 == 1) {
                        Night -= 1;
                    }
                    flag = 1;
                }
                if (flag == 1) {
                    float temp1, temp2;
                    if (flag1 == 1) {
                        temp1 = Slots - Evening;
                        temp2 = Slots - Night;
                        JOptionPane.showMessageDialog(this, "This time slot slot is full. Evening has " + temp1
                                + " Slots. Night has " + temp2 + " Slots.");
                    } else if (flag2 == 1) {
                        temp1 = Slots - Morning;
                        temp2 = Slots - Night;
                        JOptionPane.showMessageDialog(this, "This time slot slot is full. Morning has " + temp1
                                + " Slots. Night has " + temp2 + " Slots.");
                    } else {
                        temp1 = Slots - Morning;
                        temp2 = Slots - Evening;
                        JOptionPane.showMessageDialog(this, "This time slot slot is full. Morning has " + temp1
                                + " Slots. Evening has " + temp2 + " Slots.");
                    }
                } else {

                    BasicDBObject doc = new BasicDBObject("First_Name", first_name.toLowerCase())
                            .append("Last_Name", last_name.toLowerCase()).append("Batch", Batches)
                            .append("Phone_Number", phone_number).append("Age", age)
                            .append("Username", username).append("Password", password)
                            .append("Address", address);
                    Gym_Collection.insert(doc);
                    jTextField1.setText("");
                    jTextField2.setText("");
                    jTextField3.setText("");
                    jTextField5.setText("");
                    jPassword1.setText("");
                    jPassword2.setText("");
                    jTextArea1.setText("");
                    jLabel9.setFont(new java.awt.Font("SansSerif", 3, 16)); // NOI18N
                    jLabel9.setForeground(new java.awt.Color(204, 255, 204));
                    jLabel9.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
                    jLabel9.setText("Successfully Added");
                    jLabel9.setBounds(200, 10, 200, 40);

                    BasicDBObject newDocument = new BasicDBObject();
                    newDocument.append("$set", new BasicDBObject().append("Morning", Morning)
                            .append("Evening", Evening).append("Night", Night));

                    BasicDBObject searchQuery = new BasicDBObject().append("Slots", Slots);

                    Allot.update(searchQuery, newDocument);

                    setVisible(true);
                }
            }
        } catch (UnknownHostException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (NumberFormatException e) {
            JOptionPane.showMessageDialog(this, "Please Check the Data types");
            jTextField1.setText("");
            jTextField2.setText("");
            jTextField3.setText("");
            jTextField5.setText("");
            jPassword1.setText("");
            jPassword2.setText("");
            jTextArea1.setText("");
        }
    }

    else if (ae.getSource() == jButton2) {
        this.setVisible(false);
        new Admin().setVisible(true);
    }
}

From source file:Entry_OR_Exit.java

private void Entry_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Entry_buttonActionPerformed
    // TODO add your handling code here:
    /*//  w  w w  .jav  a2 s  .c  om
    setVisible(false);
    new Vehicle_type_check().setVisible(true);
    */
    try {
        MongoClient mc = new MongoClient("localhost", 27017);
        DB db = mc.getDB("parking_system");
        DBCollection collection = db.getCollection("vehicle_count");

        if (radio_vehicle_check == -99)
            JOptionPane.showMessageDialog(null, "Please Chhose Vehicle Type");
        else {
            if (radio_vehicle_check == 2) {
                int count_bike;
                BasicDBObject query = new BasicDBObject();
                BasicDBObject field = new BasicDBObject();
                field.put("wheeler_2", 1);
                DBCursor cursor = collection.find(query, field);

                BasicDBObject obj = (BasicDBObject) cursor.next();
                count_bike = obj.getInt("wheeler_2");
                System.out.println(count_bike);

                if (count_bike < 50) {
                    /*BasicDBObject searchUpdate = new BasicDBObject();
                    searchUpdate.append("wheeler_2", count_bike);
                            
                    BasicDBObject UpdateObject = new BasicDBObject();
                    UpdateObject.append("$set", new BasicDBObject("wheeler_2", count_bike + 1));
                            
                    collection.update(searchUpdate, UpdateObject);
                    */
                    setVisible(false);
                    new Veehicle_entry(radio_vehicle_check).setVisible(true);
                } else {
                    JOptionPane.showMessageDialog(null, "No Available Space For Parking 2 Wheelers");
                }
            }

            else if (radio_vehicle_check == 4) {
                int count_car;

                BasicDBObject query = new BasicDBObject();
                BasicDBObject field = new BasicDBObject();
                field.put("wheeler_4", 1);
                DBCursor cursor = collection.find(query, field);

                BasicDBObject obj = (BasicDBObject) cursor.next();
                count_car = obj.getInt("wheeler_4");
                System.out.println(count_car);

                if (count_car < 50) {
                    /*
                    BasicDBObject searchUpdate = new BasicDBObject();
                    searchUpdate.append("wheeler_4", count_car);
                            
                    BasicDBObject UpdateObject = new BasicDBObject();
                    UpdateObject.append("$set", new BasicDBObject("wheeler_4",count_car+1));
                            
                    collection.update(searchUpdate, UpdateObject);
                    */
                    setVisible(false);
                    new Veehicle_entry(radio_vehicle_check).setVisible(true);
                } else {
                    JOptionPane.showMessageDialog(null, "No Available Space For Parking 2 Wheelers");
                }
            } else {
                int count_other;

                BasicDBObject query = new BasicDBObject();
                BasicDBObject field = new BasicDBObject();
                field.put("other", 1);
                DBCursor cursor = collection.find(query, field);

                BasicDBObject obj = (BasicDBObject) cursor.next();
                count_other = obj.getInt("other");
                System.out.println(count_other);

                if (count_other < 50) {
                    /*
                    BasicDBObject searchUpdate = new BasicDBObject();
                    searchUpdate.append("other", count_other);
                            
                    BasicDBObject UpdateObject = new BasicDBObject();
                    UpdateObject.append("$set", new BasicDBObject("other", count_other + 1));
                            
                    collection.update(searchUpdate, UpdateObject);
                            
                    */
                    setVisible(false);
                    new Veehicle_entry(radio_vehicle_check).setVisible(true);
                } else {
                    JOptionPane.showMessageDialog(null, "No Available Space For Parking Trucks");
                }
            }
        }
    } catch (Exception e) {

    }
}

From source file:Entry_OR_Exit.java

private void Exit_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Exit_buttonActionPerformed
    // TODO add your handling code here:

    try {/*from   w  w w . j  a  va  2s.c o m*/
        MongoClient mc = new MongoClient("localhost", 27017);
        DB db = mc.getDB("parking_system");
        DBCollection collection = db.getCollection("vehicle_count");

        if (radio_vehicle_check == -99)
            JOptionPane.showMessageDialog(null, "Please Chhose Vehicle Type");
        else {
            if (radio_vehicle_check == 2) {
                int count_bike;
                BasicDBObject query = new BasicDBObject();
                BasicDBObject field = new BasicDBObject();
                field.put("wheeler_2", 1);
                DBCursor cursor = collection.find(query, field);

                BasicDBObject obj = (BasicDBObject) cursor.next();
                count_bike = obj.getInt("wheeler_2");
                System.out.println(count_bike);

                if (count_bike == 0) {
                    JOptionPane.showMessageDialog(null, "No 2 Wheelers in the Parking!");
                } else {
                    setVisible(false);
                    new Vehicle_exit(radio_vehicle_check).setVisible(true);
                }
            }

            else if (radio_vehicle_check == 4) {
                int count_car;

                BasicDBObject query = new BasicDBObject();
                BasicDBObject field = new BasicDBObject();
                field.put("wheeler_4", 1);
                DBCursor cursor = collection.find(query, field);

                BasicDBObject obj = (BasicDBObject) cursor.next();
                count_car = obj.getInt("wheeler_4");
                System.out.println(count_car);

                if (count_car == 0) {
                    JOptionPane.showMessageDialog(null, "No 4 Wheelers in the Parking!");
                } else {
                    setVisible(false);
                    new Vehicle_exit(radio_vehicle_check).setVisible(true);
                }
            } else {
                int count_other;

                BasicDBObject query = new BasicDBObject();
                BasicDBObject field = new BasicDBObject();
                field.put("other", 1);
                DBCursor cursor = collection.find(query, field);

                BasicDBObject obj = (BasicDBObject) cursor.next();
                count_other = obj.getInt("other");
                System.out.println(count_other);

                if (count_other == 0) {
                    JOptionPane.showMessageDialog(null, "No Others in the Parking!");
                } else {
                    setVisible(false);
                    new Vehicle_exit(radio_vehicle_check).setVisible(true);
                }
            }
        }
    } catch (Exception e) {
        System.err.println(e);
    }
}