I'll let GS support answer for certainty, but I'm pretty sure no.
We just use a Redis key as an auto incrementing counter as suggested in their docs:
var uniqueId = Spark.getRedis().incr("uniqueId");
We use this to generate object ids:
function objectId (now) { var timestamp = ((now || (new Date()).getTime()) / 1000 | 0).toString(16); return timestamp + 'xxxxxxxxxxxxxxxx'.replace(/[x]/g, function() { return (Math.random() * 16 | 0).toString(16); }).toLowerCase(); };
Thanks, that seems like a good workaround.
Jonas Aule
Hi, is there a way to generate MongoDB ObjectIDs in cloud code? For use in subdocuments/subobjects stored inside an array inside a top-level MongoDB document.
Something like this, from the NodeJS MongoDB driver:
var ObjectID = require('mongodb').ObjectID;
var generatedId = new ObjectID();
Can't find any cloud code method to do that, but I might have missed it.
Thanks