mayank451589
3 years agoNew Contributor
ReadyAPI + CosmosDB connection
Hey Team,
I am trying to connect to Cosmos DB using the connection string but I am unable to connect to the collection available in the DB. Please find the script below. Please suggest how can I connect and read the data from the Cosmos DB collection.
import com.gmongo.GMongoClient
import com.mongodb.MongoCredential
import com.mongodb.ServerAddress
import com.mongodb.BasicDBObject
import com.gmongo.GMongo
def mongo = new GMongo('Sample Connection string');
def db = mongo.getDB('prs');
log.info("DB connected")
BasicDBObject query = new BasicDBObject("policy_number","12345")
def collection = db.getCollection('cccVacPolicy')
log.info("connect with PRS DB")
def myDoc = collection.findAll();
log.info myDoc.toString();