Start a new topic

collectionAccess insert() not getting to callback()

This may be more of a Mongo problem rather than Kinvey issue, but it's interesting to say the least. Here's my code for a custom endpoint. Here's a gist:

Highlighted lines are the issue. The docs get inserted properly, but the callback never fires. I need the callback to get access to IDs.

Any ideas?

The callback never gets fired because you are calling response.complete() immediately after the insert command. The insert command is asynchronous, so as soon as its invoked, the flow immediately continues. One of the effects of calling response.complete() is that all further callbacks are cancelled.

To structure this correctly, you would call response.complete() within the insert callback.
Ah, thanks so much. That was it!
Login or Signup to post a comment