Source: site.view [edit]
Function name: incCounter
Arguments:
Description:
Page type: webl
Render function:  
Module: sandbox

Page source:

var db = Wub_GetDB("counterdb");

var coll = Wub_GetCollection(db, "counter");

var dbobj = Wub_NewDBObject([. .]); 
var res = Wub_QueryDB(coll, dbobj, 1); // 1 = max results

res;

if Size(res) == 0 then
   dbobj = Wub_NewDBObject([. value=1 .]); 
   Wub_InsertDB(coll, dbobj);
else
   var n = res[0].value ? 0;              
   n = n + 1;
   var upobj = Wub_NewDBObject([. "$set" = [. "value"= n .] .]); 
   res = Wub_UpdateDB(coll, dbobj, upobj, false, false); 
   res = n;
end;
  
res;