Read Database

Zachary Anderson
Last updated: 28 Feb 2017
Written for: Lighthouse Studio 9.3


Reads all previous responses for a given question. Any operations can then be done with this data.


  • Line 3 should be set to the name of the question whose responses will be read from the database.
  • Line 4 should be set to the data table where this question is stored. This is most likely the name of your survey followed by _data1.
  • Lines 6-9 must be filled with your database credentials.
    If you are using Sawtooth hosting, sign in to and navigate to the survey settings:
    • $databaseName likely looks like db_XXXXX.
    • $databaseUser likely looks like user_XXXXX.
    • $databasePass should be a long string of random characters.
    • $databaseHost should be a URL.


  • From line 26 on, you can write whatever Perl you wish. You could return the number of times a response appears, or determine if the newest response is a repeat, or anything else.
  • To have the Perl array returned as a JavaScript array, switch 0 with 1 on line 35. Before doing this, know that this will make it possible for any respondent to see the answers from previous respondents for this question. If responses to this question need to remain confidential, do not make this change.


You will need to upload your survey to test that this question is behaving correctly.