V8js script with mongodb preprocess HELP!

Dear friends,

I’m trying to work on building on my own custom script for further flexibilities with the use of mongodb connection. There are who simple task I would like to try, but I fail to start with some simple scripting (Sorry for being such a newbie here). What I try to accomplish is to get a count of total documents search by user email and also try extract timestamp off document ids. Below are the following scripts that I tried to create with server-side scripting. Any quick direction or example it would be great, thanks!

This is what I tried to attempt getting some script working for acquiring object id timestamps… by run either the following directly… please advise better method :sweat_smile:

var get_ts = db.comments.find({_id: {$gt: ObjectId(“5272e0f00000000000000000”)}});


if(event.response.resource) {

var myparam = {
“filter”: “_id=” + record.objectId,
var result = platform.api.get(“mongodb/_table/bigtable”, myparam);
record.from_mongo = result.content.resource[0].objectId;
var result = function (objectId) {
return new Date(parseInt(objectId.substring(0, 8), 16) * 1000);

And also I would like to run -> db.collection.find(query).count() as well by table :grin:

Another side note, if I’m taking in one email to do document create and update document fields on one script. How easily can this be accomplished with the script properly?

email: "xyz@xyz.org"

{ email: "xyz@xyz.org" },
{ email: "xyz@xyz.org",
$inc: { score: 1 }

email: "xyz@xyz.org",
category: “football”,
method: “head”