Start a new topic

Collection Hooks collection('user') forOne returning no data or error

Have had several of these Hooks set up before to send out push notifications or emails. With this new account for a new client. My problem is the logger works for calls before the forOne call but nothing is returned error or data with the forOne call. Code below:

****function onPostSave(request, response, modules) {****

var logger = modules.logger;

var collectionAccess = modules.collectionAccess

, userCollection = collectionAccess.collection('user')

, utils = modules.utils

, push = modules.push

, template = '{{name}}, the {{team}} just won!'

, pushedMessageCount = 0

, email =

, userCount;"Target email: "+;"Response ID: "+ response.body._id);"Response Owner Name: " + response.body.ownerName);

userCollection.findOne({"username":''}, function(err, doc){'Pushing message to ' + doc);

if((err) || (doc == null)){'ERROR ' + err);

} else {'DOCS ' + doc);




1 Comment

Hi, the problem is likely is that you are calling response.continue() before waiting for the findOne function to complete. The findOne function is asynchronous, and will call the callback function you pass to it when it is finished. However, your call to response.continue() happens outside of this callback. The reason your messages aren't being logged is that once response.continue() is called, your endpoint cannot do any more processing.

There are many resources online for learning how to use asynchronous javascript code/callbacks -- one example can be found at
Login or Signup to post a comment