The simplicity and scalability of document-based or NoSQL databases has made them very popular. One of the most popular NoSQL databases is MongoDB (http://www.mongodb.org/). In this recipe, we learn how to query MongoDB by calling its API using a Groovy TestStep
.
Tip
MongoDB as a service backend
Since MongoDB stores data as documents using the (Binary JSON) or BSON format, it can be convenient for use as a service or a mock backend when JSON data is required.
If you don't already have MongoDB, then install it using the instructions on the main MongoDB site (http://docs.mongodb.org/manual/installation/). I am assuming that MongoDb will be running on the usual localhost
and port 27017
. By default, no authentication is required; this will be assumed in this recipe.
To access MongoDB from Groovy, you can use the MongoDB Java driver. However, Groovy users have the option of GMongo
, which simplifies the API nicely.