Forum Discussion

anusha21's avatar
anusha21
Occasional Contributor
7 years ago

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...
  • anusha21's avatar
    anusha21
    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/gmongo

     

    import 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.MongoException

     

    def 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()
    }