Ask a Question

ReadyAPI + CosmosDB connection

mayank451589
New 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();

4 REPLIES 4
richie
Community Hero

Hey @mayank451589,

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

Cheers,

Rich
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
mayank451589
New Contributor

Hey @richie ..... Sure ... Please share the project with me asap if possible.

Hey @mayank451589 

 

digging through my old hard drive now for it,

 

cheers,

 

Rich

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
richie
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,

 

Cheers,

 

Rich

 

 

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
cancel
Showing results for 
Search instead for 
Did you mean: