Q: Couchbase document can be found in console but can’t be found in program. In console if you run the following command it will find the required document. It is working totally in the sqi env.

curl http://:8093/query/service -d ‘statement=select * from `uat` where any myorder IN orders SATISFIES myorder.id=”12345678″ END &creds=[{“user”:,”pass”:””}]’

However in the application the same statement is executed, it returns 0 result. The code looks like this:

public ServiceInventory getServiceInventoryByOrderId(final String orderId) throws ServiceInventoryException {
“select * from `” + this.bucketName + “` USE INDEX(orderid_idx) where any myorder IN orders SATISFIES myorder.id = ‘” + orderId +”‘ END”;
log.debug(“The statement we are going to execute is {}”, PLACEHOLDER_STATEMENT);

final N1qlQueryResult result = this.executeN1qlQuery(N1qlQuery.simple(PLACEHOLDER_STATEMENT));
log.info(“The size of the query result is {}”, result.allRows().size());
final List serviceInventoryList = result.allRows().stream().map(n1qlQueryRow -> {
final JsonObject document = (JsonObject) n1qlQueryRow.value().get(this.bucketName);
if (document == null) {
log.info(“Can not find anything based on {}”, this.bucketName);
return gsonObj.fromJson(document.toString(), ServiceInventory.class);

if (CollectionUtils.isEmpty(serviceInventoryList)) {
throw new ServiceInventoryException(
“Can not find a matched Service Inventory Object by orderId = ” + orderId);

return serviceInventoryList.get(0);


A:Why it is so weird? Why it is working ONLY in console?

In the method executeN1qlQuery(…) log.debug(“bucket.query time = [{}] “, System.currentTimeMillis() – startTime); can be executed, it got stuck in bucket.query(query). So what is the connection string in the bucket?
There is an assumption here, the connection String in the code is the same as the command I ran in console. But is it really the same? No. If you replace stl-nbn-cb45e-uat-cl001.np.stl.np.top.corp.telstra.com with the connection string I use in code, the execution of the command will be failed.