Schedule script to change status of a mongodb document value


Hello eveybody
i use DF 2.1 with mongodb service
very nice , no problem

now i’m looking on this functionality :
imagine that i have a mongo collection with document …
on this document lets say i have:
{ “ISOstart” : ISODate(“2016-05-02T21:08:02.246+0000”),
“status”: “confirmed”}

what i want to do; is to setup a script (outside the application) that i can schedule
where i get all document with my ISOstart date , that is older that toady (new Date() ) and update the status to (for example) : "archived’

i had a look at “Script” tab on the DF admin dash, but not sure that it is made for this
i had also a look in scripting service… but again not sure it will do the job

if some of you could give me some advice…



If you don’t have a huge number of records to update you could create a custom script service named ‘archive.’ The service would call platform.api.get() with a date filter, update the status, then use platform.api.put() to save the changes. To call the script you would do this:

POST /api/v2/archive

The script would figure out today’s date and make the required API calls.


so for example (just to test)
i create a script service with

var t = {“resource”:[{“cool”:“very”}]}
var t = JSON.stringify(t) parkmeDB/_table/comments ,t );

then when i call it with http://mydreamfactoryserver/test_rest.html;

i got a : error “context”: null,
“message”: “Array to string conversion”,
“code”: 500,

what i’m doing wrong here?


I think you don’t need to stringify it. Also are you missing some semi colons at the end of each statement? And you forgot the quotes too :slight_smile:

All you need is “parkmeDB/_table/comments”, {“cool”:“very”} );


thanks for your reply
unfortunaly with “parkmeDB/_table/comments”, {“cool”:“very”} );

when i test it via DSPURL//test_rest.html

with POST as method i dont have any output

maybe there is a way to test it via CURL?


You can simply do this to test:

var result = "parkmeDB/_table/comments", {"cool":"very"} );

You should be able to see the result in the browser console. And also if the post is successful you will find a new record in your table called “comments”


hi M_menon
i got absolutely the same “Array to string conversion” …
i think that the problem is that i use df test_rest.html page to Post
and of course i dont have any new records in my mogodb
i’m looking on a way to do a curl post to test my script


This is a working example

var payload = {
	"resource": [{
		"field_name": "SomeArbitraryValue"
var result ="db/_table/tblComments", payload);
event.response.status_code = 200;
event.response.content_type = "application/json;charset=utf-8";
event.response.content = result; // You can get the staus_code from this content too

You should be able to see the result in your browser. Just make sure that you have a table by the name of tblComments and the path is correct (If we go by the sqlite table then the path is as shown in my example)

Also ensure that you have a field by the name of “field_name” (as per my example). I am pretty sure the above will work :slight_smile:


YES!! it works now
i will try to do some operation with json
put it in a cron and let you know
thanks again