Description
Since upgrading from the 3.x to 4.x Node SDK, the default for running queries is now
{adhoc: false}. I'm not sure if this change was intentional or not, but it does cause anyone upgrading who runs "EXPLAIN" queries to fail at runtime as it attempts to EXPLAIN the EXPLAIN.
I believe one of two solutions make sense:
- Return the default back to the 3.x default of
{ adhoc: true }
. This may make sense because it is currently unnecessarily running prepares on many queries for which it may be unwarranted. That said, this change could be considered breaking, and also the original change may have been intentional in the 4.x series.
- When defaulting the "adhoc" option, use a regex to see if the query being run starts with "EXPLAIN". Something like {{ /\s*EXPLAIN\s/i}} should do the trick. If present, in that case only default adhoc to true. So perhaps adhoc: options.adhoc !== undefined ? !!adhoc : /\s*EXPLAIN\s/i.test(query),
Note that this also may relate to this bug I found where prepared ALTER INDEX queries don't behave as expected: https://issues.couchbase.com/browse/MB-53264