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.


#4

Support Async/Await and Promise as well…This is crucial !nowadays


#5

Hey @max_xyz,

Our 3.0.0-alpha.1 release was published last week. This is obviously an early release (alpha), but it does support many of the features of the 2.0 SDK and includes native support for Promises, Async/Await/etc… throughout the library!

Cheers, Brett


#6

@brett19
I looked into the new 3.x code.
But, It looks like there are many breaking changes in the new version to support native async/await and new syntax with ES6…
So We need a sample CRUD example project. the test codes are hard to follow for now.
Please provide essential documentation and sample project ASAP…Please