package com.actionsoft.bpms.org.event;
import org.bson.Document;
import com.mongodb.MongoClient;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
public class MongodbUtil {
private static volatile MongodbUtil mg ;
private MongoCollection<Document> collection;
private MongodbUtil(){}
public static MongodbUtil getInstance() {
if (mg == null) {
synchronized (MongodbUtil.class) {
if (mg == null) {
mg=new MongodbUtil();
MongoClient mongoClient = new MongoClient( "192.168.1.47" , 27017 );
MongoDatabase mongoDatabase = mongoClient.getDatabase("hool");
System.out.println("Connect to database successfully");
MongoCollection<Document> collection = mongoDatabase.getCollection("test");
mg.setCollection(collection);
}
}
}
return mg;
}
public MongoCollection<Document> getCollection() {
return collection;
}
public void setCollection(MongoCollection<Document> collection) {
this.collection = collection;
}
}