dataBase.Connect.java Source code

Java tutorial

Introduction

Here is the source code for dataBase.Connect.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package dataBase;

import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.MongoClient;
import com.mongodb.ServerAddress;

/**
 *
 * @author Rodrigo Rivas
 */
public class Connect {

    private MongoClient cliente;
    private DB db; //Base de datos de MongoDB
    private final String dbName = "Pruebas"; //Nombre de la base de datos
    private DBCollection collection;

    public Connect() {

        cliente = new MongoClient(new ServerAddress("localhost", 27017));
        System.out.println("Conexion establecida");
        db = cliente.getDB(dbName);

    }

    public void Collection(String collectionName) {
        collection = db.getCollection(collectionName);
    }

    public MongoClient getCliente() {
        return cliente;
    }

    public void setCliente(MongoClient cliente) {
        this.cliente = cliente;
    }

    public DB getDb() {
        return db;
    }

    public void setDb(DB db) {
        this.db = db;
    }

    public DBCollection getCollection() {
        return collection;
    }

    public void setCollection(DBCollection collection) {
        this.collection = collection;
    }

}