Connecting to Mongo DB is Timed Out
- 7 years ago
I solved it by myself by using below code (i have already placed gmongo jar and also mongo java driver jar)
I downloaded mongoDB drivers from here http://mvnrepository.com/artifact/org.mongodb/mongo-java-driver
and here http://mvnrepository.com/artifact/com.gmongo/gmongoimport com.gmongo.GMongo
import com.mongodb.BasicDBObject
import com.mongodb.DB
import com.mongodb.DBCollection
import com.mongodb.DBCursor
import com.mongodb.*
import com.mongodb.MongoExceptiondef javaMongo = new MongoClient(new MongoClientURI("mongodb://xxxxx:xxxxx/?ssl=true&replicaSet=globaldb"))
def db = javaMongo.getDB('DBName')
def table = db.getCollection("DBTbleName");def query = new BasicDBObject("UserId", "XXXXX")
def cursor = table.find(query)
try {
while(cursor.hasNext()) {
log.info cursor.next()
}
} finally {
cursor.close()
}