I'm new to appery and am walking through the tutorials and experimenting purely for learning purposes.
I have a database with a long list of words in it. In fact, it's a Scrabble-like list of all of the words in English. I wish to return all of the words in the database that begin with a specific string of letters. Again, for learning purposes, I want to do this server-side (not application side).
So far, so good. I've found a lot of documentation on this and have successfully achieved what I've set out to do ... with one difficulty: my server code is only returning the first entry it finds in test output. For example, in the code below, I've hard-coded a request to return all words beginning with "da". The script successfully returns "dab", but not "dabble" or "daft", etc. I'm looking to receive all 25 words (or how many ever there are).
The actual response is as follows:
{
"message":"53043eefe4b0e3176f3fa375 dab"
}
So, my question today is: what am I doing wrong? Please see my code, below:
---------------var responseBody = {},
requestParams = {},
paramKeys = request.keys();
// Code learned from tutorials - this should look familiar to appery staff
for (var key = 0; key < paramKeys.length; key++) {
requestParams[paramKeys[key]] = request.get(paramKeys[key]);
}
// Declare database ID and Master key
var dbId = "123abc...";
var masterKey = "123abc...";
// Get the requested words from request parameters
var word = requestParams['word'];
var db = "https://api.appery.io/rest/1/db/colle..."
try {
// Get the word from the database - here I've hard-cded a request for "da"
var XHRResponse = XHR.send("GET", "https://api.appery.io/rest/1/db/colle...", {
"headers": {
"X-Appery-Database-Id": dbId,
"X-Appery-Master-Key": masterKey
},
"parameters": {
"where": '{"word":{"$regex":"da", "$options":"i"}}'
}
});
// give me the words as well as their database IDs
var retrievedInfo = XHRResponse.body[0]["_id"] + " " + XHRResponse.body[0]["word"];
responseBody.message = retrievedInfo
response.success(responseBody, "application/json");
} catch (e) {
response.success("message: " + e.message + "\ncode: " + e.code); //If something goes wrong, error message appears
}
// what I receive is "message":"53043eefe4b0e3176f3fa375 dab" Can you help?
// PS: yes, I will feel silly once you give me the answer.