Forum Discussion

martinrampton's avatar
martinrampton
Occasional Contributor
6 years ago
Solved

Retreiving data from Mongo db using Groovy and assigning it to a test case property

Hi, I'm looking to create a test step that can connect to MongoDB, run a query, and then assign the result to a test case property. I have the connection working and I can retrieve a result as a row ...
  • TNeuschwanger's avatar
    6 years ago

    hello martinrampton,

     

    that query looks a little out of place...   Maybe just stick with the collection to debug for a little bit then add the query.

    .

    .

    def db = mongo.getDB('digital')
    def collection = db.getCollection('QuoteSummary')

    log.info collection.find().first();

    // or

    Document myDoc = collection.find().first();

    log.info myDoc.toString();

    // or

    log.info myDoc.toJson();
    .

    .

    if you can identify content in the collection, you can start forming query.

    i.e.

    myDoc = collection.find(eq("workReferenceNo", "GPE0024879")).first();

    log.info myDoc.toString();

    // or

    log.info myDoc.toJson();