The Document Repository CRUD Tool uses MongoDB Javascript-based querying to perform actions like creating, updating, or deleting LLM-friendly MongoDB document style data in document repositories. For a similar tool that uses graphical-based querying on record type data created from traffic, see the Data Repository CRUD Tool. You can add it to a test or responder via the Add Output wizard (SOAtest or Virtualize) or as a standalone test in SOAtest.
The Document Repository CRUD Tool executes a MongoDB script to perform CRUD operations on the document repository. It has three built-in arguments: db, input, and context. When it is attached to a responder, there is a fourth built-in argument: request.
Typically, you will want to organize your script in three parts:
request, input, and context. Make sure the values are converted to the data type expected for the documents.db to add, update, or perform other operations on the documents as necessary.
|
The db argument is the interface through which MongoDB script commands are performed on the document repository. Some examples include:
db.createCollection("items")db.items.insertOne({ id: 1, name: "Wireless Headphones", price: 79.99 })db.items.findOne({ id: 1 })db.items.updateOne({ id: 1 }, { $set: { price: 69.99 } })db.items.deleteOne({ id: 1 })This argument supports most MongoDB script commands and options. For more information, refer to the official MongoDB documentation.
The request argument is a JSON object that contains the incoming request if this tool is attached to a responder. It includes the headers, the path parameters, the query parameters, and the body (converted to JSON). The JSON object looks like this:
{
"headers": {
"Host": "localhost:9080",
"Accept": "application/json"
},
"pathParams": {
"accountId": "3455532744"
},
"queryParams": {
"keyword": "Electronics",
"limit": "25"
},
"body": {
"startDate": "2026-01-01",
"endDate": "2026-03-31"
}
} |
The input argument is the content to which this tool is chained. For example, when the tool is chained to an Incoming Transport Header the value of input is the request header or, when it is chained to an Incoming Request, it's the request payload.
When the tool is used as a standalone test, the content is defined on the Input tab.
The context argument is an instance of ExtensionToolContext through which you can access suite variables and data banks. To learn more about ExtensionToolContext or ScriptingContext, go to Parasoft > Help or Help > Help Contents, depending on your installation, and look for the Extensibility API books.
You can configure virtual assets that use a Document Repository CRUD Tool to return an HTTP error response when certain conditions exist in the repository. For example, you might want to see an "HTTP 404" error when an item does not exist in the repository. To do this:
throw statement to your Document Repository CRUD Tool script in the format:throw "<httpStatusCode>_<errorMessage>"; |
var item = db.items.findOne({ id: 1 })
if (item == null) {
throw "404_Item does not exist";
} |
crudToolErrorCode and crudToolErrorMessage."404" = "${crudToolErrorCode}"crudToolErrorCode as the HTTP response code. See Message Responder Overview for more information about configuring responders.