I was using Node.js SDK 4.1 to run a simple query against a Couchbase 6.6 Community Server with the code below:
try {
const cluster = this.cluster();
let query = `SELECT meta(doc).id, * FROM \`${bucket}\` AS doc WHERE type = '${type}' and owner = '${uid}' `;
if (start && typeof (start) === 'number') {
query += ` AND time >= ${start} `;
}
if (stop && typeof (stop) === 'number') {
query += ` AND time < ${stop} `;
}
query += ' ORDER BY time ';
query += (asc && typeof (asc) === 'boolean' && asc === true) ? ' ASC ' : ' DESC';
if (limit) query += ` LIMIT ${limit}`;
if (offset) query += ` OFFSET ${offset}`;
cluster.bucket(bucket);
const { rows } = await cluster.query(query);
res.send({
data: rows,
});
logger.info(`Query ${query} executed successfully with ${rows.length} row(s) returned.`);
} catch (error) {
handleErr(error, res, logger);
}
The result seems to be spotty; the query sometimes ran without any problem, but sometimes a PreparedStatementFailureError was thrown.
I tried to execute/prepare the same query manually in the Web console UI. It ran without a hitch.
Does anyone have similar problem?
Is there something to do with the timeout parameter?
Any tips will be highly appreciated.