How can I create a group in my query service and set a limit on the values returned?
Once you get all records (1st request), you would traverse the data you received in JavaScript and get only the values that you need.
Catch up wih the Appery.io community on our forum. Here you'll find information on the lastest questions and issues Appery.io developers are discussing.
https://forum.appery.io/
Once you get all records (1st request), you would traverse the data you received in JavaScript and get only the values that you need.
Yes, that is what I need help with.
What do I do with value? How do I sort the $ response that holds all the row?
Can you help me with this? Can anyone?
Hello!
1) you would need to retrieve list of all groups (it should be distinct request, take a look here)
2) for each group you would need to retrieve the latest record in collection (but it's not that easy to do with a few REST requests). Perhaps it would be easier with Server code
In any case Appery.io DB doesn't allow to do aggregation. That's why you can't retrieve data with only one request.
Hi there,
The only experience I have with MongoBD and Appery.io is by using your Services and dragging relations between a request/response and my page elements.
If I need to code anything and skip the services offered in the UI, I will need more technical help on how to achieve this and not use a standard Database Service.
Thanks!
Hi, usually custom code and custom app logic are outside the scope of our support, but we'll be glad yo help if you describe in more details what you did and what doesn't work.
Alright, let me do some more research and see what I can come up with.
Just to confirm, MongoBD doesn't offer the use of a max(_updatedAt) value in the select? This would definitely fix my problem!
Appery.io uses MongoDB and MongoDB allows max(_updatedAt), but Appery.io API doesn't allow it unfortunately.
Alright, I am back after doing a few tests.
I created a table that has all the groups, so:
Table A
dog
cat
bird
And I load my list with a simple list query. Once I feed each dynamic list item with a group name, I added a Javascript function that looks like this:
$.ajax({
type: "GET",
beforeSend: function (request) {
request.setRequestHeader("X-Appery-Database-Id", "MYBDID");
},
url: "https://api.appery.io/rest/1/db/colle...",
data: {animalname:value},
dataType: "json",
success: function (response) {
alert(JSON.stringify(response))
},
error: function (xhr, ajaxOptions, thrownError) {
alert("Error");
}
});
This request works and is being loaded on each list item. What I can seem to figure out is where can I add my limit=1 and my sort=-updatedAt?
I have tried added it with &= values in the data query but it doesn't work and breaks my page.
Is there any documentation on each to write a full ajax request with your system? I have found no doc on the curl requests (except on how to edit the actual curl codes that I find in my databases but no idea how to implement them so I have resorted to Ajax).
Thanks!
Hi, to make correct request to DB you need to send "where", "limit", "sort" parameters the following way:
code$.ajax({
type: "GET",
beforeSend: function(request) {
request.setRequestHeader("X-Appery-Database-Id", "MYBDID");
},
url: "https://api.appery.io/rest/1/db/collections/MYTABLE2",
data: {
//Request parameters:
where: JSON.stringify({animalname:value}),
limit: 1,
sort: "-updatedAt"
},
dataType: "json",
success: function(response) {
alert(JSON.stringify(response))
},
error: function(xhr, ajaxOptions, thrownError) {
alert("Error");
}
});/code
Please note you have incorrect column name "updatedAt", it should be "updatedAt"
Ok so I am now getting the first row like I need and it works great!
Now my issue is that I want to achieve this in the success function and it bugs.
function (response) {
Appery('numberOfCookies').text(response[0].numberofcookies);
}
My list looks like this:
Label: Animal Name
Label: Number of cookies
My label Animal Name gets set automatically by the response data I receive from the List Service of the Animal Collection.
On that label, I have added Javascript, so the Ajax request we just saw to make a second query to another collection that has the number of cookies updates for each animal.
On my success function, I do receive the right data so the number of cookies for each row. In that function, I would like to set the value of the second label in Javascript.
But that's where it fails and bugs my page. How can I assign a value to a label during a loop?