0% found this document useful (0 votes)
14 views1 page

Conexion

This Java class connects to a MongoDB database, opens a collection, and closes the connection. It takes in database and collection names as parameters and returns the collection to allow performing operations on it.

Uploaded by

mendezpi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views1 page

Conexion

This Java class connects to a MongoDB database, opens a collection, and closes the connection. It takes in database and collection names as parameters and returns the collection to allow performing operations on it.

Uploaded by

mendezpi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

package DAO;

import org.bson.Document;

import com.mongodb.client.*;
import com.mongodb.MongoClient;

public class Conexion {


public static MongoClient mongoClient;
public static String servidor="localhost";
public static int puerto=27017;

public static MongoCollection<Document> AbreColeccion(String nombreBD, String


nombreCol)
{
mongoClient = new MongoClient(servidor, puerto);
MongoDatabase db = mongoClient.getDatabase(nombreBD);
MongoCollection<Document> col = db.getCollection(nombreCol);
return col;
}

public static void Cierra()


{
mongoClient.close();
}
}

You might also like