Start a new topic

schedule a daily query

Hello, I need to know how to schedule a daily query to a database. Basically it will erase an element from the database.

Is it posible to do it through Kinvey? Can anyone help me?



Thanks, Yael


Hi @yaelhh‌,



Kinvey handles date/time values in [ISO8601](http://en.wikipedia.org/wiki/ISO_8601) format (eg *2014-09-11T20:40:58.694Z*)
Thanks for your quick response.

I fixed what you told me but it still doesn't work.



Which format Date() should have? the field fechaVigencia is 16-Set-2014.



Thanks
Hi @yaelhh‌,



The mongo operators in your query should not be surrounded by whitespace ("$and", not " $ and ")



Thanks
Hi



I have created the endpoint, but it is not erasing from the database, could you help me?

The idea is to erase the line that matches with: fechaVigencia = today and pago = false



Thanks again.



function onRequest(request, response, modules) {

date= new Date();

modules.collectionAccess.collection("Compra").remove({"fechaVigencia" : {" $gte ": date}, " $and " : {"pago" : {" $gte ": false}}}, function (err, docs) {

if (err) {

logger.error('Query failed: '+ err);

} else {

response.body = docs;

response.complete(200);

request.body=docs;

}

});



}
Hi Yael,



The API reference for the collection access module is [here](http://devcenter.kinvey.com/rest/reference/business-logic/reference.html#collection-access-module). You will be able to delete your document with this.



Once you have written your endpoint you can schedule a weekly run using the schedule popover in the business logic editor like this...



![](https://c3409409.ssl.cf0.rackcdn.com/kinvey.vanillaforums.com/editor/pt/uswh8he2r0ph.png "")
Login or Signup to post a comment