Forum Discussion
http://www.codeconfuse.com/2014/03/mongodb-convert-data-getting-from.html
- Deepali9 years agoOccasional Contributor
Thanks Rao for your help...but I have already tried this...but no luck.
- nmrao9 years agoChampion Level 3Was that your complete script? Can you post the stacktrace from error.log? By the way how many records that you get in the collection.
- Deepali9 years agoOccasional Contributor
import com.mongodb.*
import com.mongodb.MongoCredential as MC
import com.mongodb.ServerAddress
def credential = MC.createMongoCRCredential( "<username>",
"<DBname>",
"<pwd>".toCharArray() )
def mongoClient = new MongoClient( new ServerAddress("<server sddress>"), [ credential ] )log.info "Connect to database successfully"
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"
}Stack trace:
2016-01-25 15:56:32,000 ERROR [errorlog] org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'DBCollection{database=DB{name='qahmedb'}, name='Hotel'}' with class 'com.mongodb.DBCollection' to class 'com.mongodb.DBCursor'
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'DBCollection{database=DB{name='qahmedb'}, name='Hotel'}' with class 'com.mongodb.DBCollection' to class 'com.mongodb.DBCursor'
at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnSAM(DefaultTypeTransformation.java:405)
at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnNumber(DefaultTypeTransformation.java:319)
at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:232)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.castToType(ScriptBytecodeAdapter.java:603)
at Script43.run(Script43.groovy:15)
at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:92)
at com.eviware.soapui.support.scripting.groovy.SoapUIProGroovyScriptEngineFactory$SoapUIProGroovyScriptEngine.run(SoapUIProGroovyScriptEngineFactory.java:76)
at com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.run(WsdlGroovyScriptTestStep.java:155)
at com.eviware.soapui.impl.wsdl.panels.teststeps.GroovyScriptStepDesktopPanel$RunAction$1.run(GroovyScriptStepDesktopPanel.java:263)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)With condition City_en : 'Orlando', it has 3 records, while in total it has 500+ records.
It gives successful result when done without any condition in find query.
Related Content
- 2 years ago
Recent Discussions
- 5 days ago
- 10 days ago