As of April 12th, you must go to Progress SupportLink to create new support cases or to access existing cases. Please, bookmark the SupportLink URL and use the new portal to contact the support team.
Our findAndModify query worked perfectly a day or two ago, but now it never calls the callback. It does the upsert operation correctly, but then just appears to die.
I saw that there was a resent update, could this have broke our query? It could be that we implemented it wrong, and the fix could have broken our incorrect implementation?
Not quite sure, although we are dealing with several layers of callbacks, so we need to try to untangle them.
What happens if you just try to execute the query in isolation, by itself, without the request and the async? Try running one query with a statically-defined 'result' object, in the main body of onRequest, commenting out the other code and putting response.complete in the query callback?
T
Tony Lenz
said
almost 10 years ago
Agreed, but logger.error(err); is never being called. So, I am inclined to say that is not the case.
From our probing, it looks like the findAndModify call is the last thing that is called (in parallel). Do you see anything wrong with that call?
Thanks!
M
Michael
said
almost 10 years ago
Is it possible that one of the array elements is causing an error in parseResult? The parseResult functions are called for each element of the array in parallel, and if an error occurs in any of them, the callback from async.map is immediately called with the error, which will call response.complete. This causes all further callbacks to be cancelled.
T
Tony Lenz
said
almost 10 years ago
I wanted to avoid that, but here it is. Thanks for looking into it. :)
```var GOOGLE_PLACES_API_KEY = 'KEY';
function getDistanceInMiles(lat1,lon1,lat2,lon2) {
// Courtesy of http://stackoverflow.com/questions/27928/how-do-i-calculate-distance-between-two-latitude-longitude-points
var R = 3963.1676; // Radius of the earth in miles
Where is your response.continue or response.complete calls? If either is called before the callback is invoked, the callback is cancelled and execution stops.
Tony Lenz
I saw that there was a resent update, could this have broke our query? It could be that we implemented it wrong, and the fix could have broken our incorrect implementation?
Any help would be appreciated. Thanks :)
CODE:
var logger = modules.logger;
var collections = modules.collectionAccess;
var places = collections.collection('places');
...
//modules.async.map calls parseResult
var parseResult = function(result, callback) {
logger.info(result);
places.findAndModify({gp_id : result.id}, [], {
gp_id : result.id,
gp_ref : result.reference,
name : result.name
}, {new:true, upsert:true, w:1}, function(err, doc) {
logger.info('callback');
if (err) {
logger.error(err);
} else {
logger.info(doc);
var placeLat = result.geometry.location.lat;
var placeLng = result.geometry.location.lng;
var distance = getDistanceInMiles(lat, lng, placeLat, placeLng);
var place = {
name : result.name,
id : doc.entity._id,
reference : result.reference,
rating : result.rating,
location : {
lat: placeLat,
lng: placeLng
},
distance : distance,
iconUrl : result.reference
};
callback(null, place);
}
});
};