elenal
9 years agoOccasional Contributor
MongoDB connection fails in ReadyAPI 2.2.0
Hi!
I have a following script to connect to Mongo which I am using in SoapUI Free version and it's working fine:
@Grab(group='com.gmongo', module='gmongo', version='1.5')
import com.gmongo.GMongo
import com.mongodb.MongoCredential
import com.mongodb.*
import com.mongodb.ServerAddress
import com.gmongo.*
import com.mongodb.MongoURI
import com.mongodb.DBCursor;
import com.mongodb.BasicDBObject;
import com.mongodb.BasicDBList
def mongoendpoint = context.expand( '${#Project#mongoendpoint}' )
def mongocollection=context.expand( '${#Project#mongocollection_ignition}' )
def mongo= new GMongo (new MongoURI(mongoendpoint))
def clientId = context.expand( '${#Project#clientId}' )
def db = mongo.getDB(mongocollection)
def collection = db.getCollection("Collection")
def test=collection.findOne(_id:clientId).toString()
log.info ("Mongodb parsing finished")We recently upgraded to paid version (ReadyAPI 2.2.0) and I'm getting errors when executing the same script:
Username/password are supplied as part of mongoendpoint variable.
Is ReadyAPI using a different approach? Was trying using mongoClient authentification instead. Connection is set up, but I'm getting timeouts when it actually fetches data
def credential = MongoCredential.createMongoCRCredential('s**','admin', '**'.toCharArray())
def mongoClient = new MongoClient( new ServerAddress("**", **), [ credential ] )
def db = mongoClient.getDB(mongocollection)
def collection = db.getCollection("**")
assert collection instanceof com.mongodb.DBCollection
// get timeout if try to execute findOne
collection.findOne(**).config