Start a new topic

TypeError when trying to update entity in data store

Hi, guys.



I've ran into a problem where (occasionally, not always) my endpoint throws a BLRuntimeError with the debug message `TypeError: Cannot call method 'call' of undefined`. I tried inserting some log statements to lower down the problem to a single line, and it seems to be when I do a .update() on a collection. My code looks similar to this:



```

var onRequest = function (req, res, mods) {

var ds = mods.collectionAccess.collection('dsdb');

ds.findOne({ _id: req.body._id }, function (err, dsrow) {

if (!err && !!dsrow) {

dsrow.prop = req.body.val;

ds.update(dsrow, function () {

res.body = 'Updated data successfully';

res.complete(200);

});

}

});

};

```



I find it strange that the error only occurs sometimes, and it is not caught by a try/catch statement around my entire endpoint.



All comments are appreciated! Thanks.

Hi Karisma,

Code looks similar to this or is this?
Karisma, I am trying to clarify if this is the code you are using, or like you said this is "similar" to the code you are using.
This is similar. I can't disclose the actual code due to some confidentiality issues.
Okay, so I am assuming that you're using shorthand for some of your code? Like res.complete is actually response.complete in your code?
Yes, and req is request and mods is modules.
Hey Karisma,

The callback requires three arguments; error, response, and body. See also http://devcenter.kinvey.com/rest/reference/business-logic/reference.html#collection-access-module

That could be the issue.
Login or Signup to post a comment