async using node.js HapiJS and couchbase sdk returning empty results


#1

So I have the following code which is in a Hapi.JS handler, and is attempting to call couchbase sdk.

handler: async (request, h) => {
                var SpatialQuery = Couchbase.SpatialQuery;
                var sw = JSON.parse(request.payload.sw);
                var ne = JSON.parse(request.payload.ne);
        
                var query = SpatialQuery.from('dev_spatialtest', 'spacetest').limit(100);
                return await myBucketQuery(query);
            }

It calls this function

async function myBucketQuery(query){
    return bucket.query(query, async function(err, results){
                console.log("in results = " + JSON.stringify(results));
                return results;
            });
};

the console.log in myBucketQuery returns the correct result, but does it after the hapi has already returned (or maybe not???) The result in postman comeback as

{
    "_events": {},
    "_eventsCount": 2
}

can anyone give me a clue what I am doing wrong here??


#2

Hey @leerlemoniii,
Unfortunately the Node.js SDK does not support promises as you have used them. You will need to use a promisification library to translate your Promise-based code to callback-based for the Couchbase SDK. We are hoping to make this available soon though!
Cheers, Brett


#3

Any update on this? This issue is making me switch to a competitor database. Already switched from KoaJS to Hapi, because of the tutorials on your blog (and others). Just to find out that it won’t work either, because newer versions of Hapi require handlers to provide a Promise/return value. There are two nodejs couchbase promisification 3rd party librarys available, both of which don’t work with Couchbase 5 (mainly because of authentication). Do we really need to write our own SDK to interact with Couchbase? Please update couchnode for modern standards.