Forum Discussion

Deepali's avatar
Deepali
Occasional Contributor
9 years ago

How 'find' command to be used to fetch results from mongoDB using groovy in soap ui

Below is the groovy code snippet I have written.

 

DB db = mongoClient.getDB( "qahmedb" );
DBCollection coll = db.getCollection("Hotel");
log.info "Collection Hotel selected successfully"

DBCursor cursor = coll.find({City_en : 'Orlando' });
List list1 = new ArrayList();
while( cursor.hasNext() )
{
def hotel = cursor.next()
log.info "Found Hotels with ID $hotel._id and name $hotel.Title_en"
}

 

It is leading to error message as "ERROR:An error occurred [Cannot cast object 'DBCollection{database=DB{name='qahmedb'}, name='Hotel'}' with class 'com.mongodb.DBCollection' to class 'com.mongodb.DBCursor'], see error log for details"

 

While if I am using direct find query without any condition like DBCursor cursor = coll.find();

It gave results successfully without any error.

 

Kindly help with the possible solutions.

 

Thanks

Deepali