Start a new topic

Can't change model in pre-save hook

I have a need to generate auto-incrementing numbers. I added onPreSave business logic script which worked fine until today (well, I found it today). Here's the script:

function onPreSave(request, response, modules){

var collectionAccess = modules.collectionAccess,

body = request.body;

if (typeof body.uniqueId !== 'number') {

collectionAccess.collection('Counters').findAndModify({name: 'estimate'}, [], {$inc: {'counter': 1}},

function(err, doc) {

body.uniqueId = doc ? doc.counter : 0;



} else {




Unfortunately, Kinvey changed what is returned in `doc` argument to the callback function. Before it document with updated value, not some sort of following object:


entity: {...},

updatedExisting: true


Is this documented change and it will stay like this in the future?

P.S. I can't edit my own message here.
Hi Serge- We found an error with count and deployed a fix-- can you confirm if you are still having this problem?
Works, thank you.
Login or Signup to post a comment