N1ql Query Inconsistent Results

Hi,

When I run my n1ql query using the nodeJS SDK, I always get different results ranging from ~3000-5000 resultCount. But when I run the same query in the query console, I always get the expected resultCount of ~8500.

Can someone please point me to where I should fix the issue? I’m running 4.5.1-2844 Community Edition.

Thanks in advanced!

Hi,

Can you post up the query that you’re putting into the console and a snippet of the code that you’re running against the SDK?

Hi @chvck,

Sure! Here’s query I use in the console:


And here’s a snippet of what I use against the nodeJS SDK

var query = n1ql.fromString("
SELECT
merc.first_name || " " || merc.last_name AS name,
merc.area, merc.fmas, merc.channel, merc.designation,
answer.topic,
answer.module_name,
MILLIS_TO_ZONE_NAME(answer.date_created, ‘Asia/Manila’) AS date_taken,
answer.score,
answer.question_count,
(answer.score/answer.question_count * 100) AS percentage,
answer.passed AS status
FROM ami_training AS merc
LEFT OUTER JOIN ami_training AS answer ON KEY ‘User|’ || answer.owner FOR merc
WHERE
merc.type=‘User’ AND merc._deleted IS MISSING AND (merc.is_active IS MISSING OR merc.is_active)
AND answer.type=‘Answer’ AND answer.year=2018 AND answer.quarter=1 AND answer._deleted IS MISSING
ORDER BY merc.last_name";
bucket.query(query, function(err, data) {
// handle response
});

They’re exactly the same statement but nodeJS responses vary between 3k and 5k responses.
Thanks!

That’s odd, what version of Node and the Node SDK are you using?

I’m using couchbase 2.4.3 SDK and node 6.10.3

Do you know how long the query is taking to return via the SDK? Have you altered the timeout at all too?

It’s around 1 min. Yeah, I changed the timeout to 300 seconds so timing out shouldn’t be an issue.

I used the REST API in the meantime as it returns a more consistent result.

Hi, interesting. If you’re seeing differing numbers of results each time then it feels like a timeout or similar. Have you tried bumping the log level to see if there are any clues there? (e.g. LCB_LOGLEVEL=5 node index.js)

I’ll try to check out the logs and update you if I find anything.

Thanks!