Connecting to Mongo DB is Timed Out
HI ALL,
at my workplace we are using Mongo Document DB so would you please give me steps to connect to DB, This is really high priority for me please help on this
I am using groovy script to connect to Mongo DB and i am using below lines of code and it is giving me error as follows
import com.gmongo.GMongo
def mongo = new GMongo('HOSt And PORT')
def db = mongo.getDB('DB Name')
log.info db.Permissions.findOne()
Note: I Kept gmongo-1.5.jar and also mongo-java-driver-3.2.2.jar files in location C:\Program Files\SmartBear\ReadyAPI-2.2.0\bin\ext
Error i am getting is as follows
An error occurred [Timed out while waiting to connect after 10000 ms], see error log for details
Your reply will be appreciated
Thanks
Anusha
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()
}