Just a quick two questions if I may;
You can use scriptData to attach data to responses. If you were to take "queryResult" Spark.setScriptData("result", queryResult) as a valid mongo query this would essentially print the result in scriptData.
To set data passed in through a LogEventRequest in the response you would simply use Spark.getData().attributeShortCode to get the value passed in and then set it to scriptData using the method above. Does that make sense ?