Forum Discussion

mayank451589's avatar
New Contributor
2 years ago

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');"DB connected")
BasicDBObject query = new BasicDBObject("policy_number","12345")
def collection = db.getCollection('cccVacPolicy')"connect with PRS DB")
def myDoc = collection.findAll(); myDoc.toString();

4 Replies

  • richie's avatar
    Community Hero
    Hey mayank451589,

    I think i have a CosmosDB ReadyAPI project saved somewhere. I'll try and dig it out, it might help.


      • richie's avatar
        Community Hero

        Hey mayank451589 


        I found it - this isn't one of my projects - I think I found this on the web somewhere and saved it cos I thought - "I might have to test a CosmosDB endpoint one day"


        I'm attaching the whole project - you'll have to edit the custom project level properties for your instance - but I think this will allow you to connect.  the first testcase appears to have all the different REST requests to call all the different info you'd want - a Collection, All Collections, documents, etc.


        Have a look and see if it helps,