Document not immediately available to be queried against

n1ql

#1

I have noticed that documents may not always be immediately available to be queried against after they’ve been created. I created a document via sync gateway, and can retrieve the document from sync gateway, and can also retrieve the document from the admin console by using the “Lookup ID” after clicking on “Documents” button for the bucket, but if I go to the Query tab in the console and query for that meta().id, it is not returned in the result.
I am running couchbase server 4.5 enterprise edition.
Has this problem come up before? Should the document become available, I will update


#2

The primary index is updated asynchronously with respect to the document insert. What you are observing is normal. From an SDK or the REST API you can use the appropriate scan_consistency to ensure that all acknowledged documents are in the index.

If you want to just do a simple document lookup, from the list of buckets click “Documents” on the right hand side of the row, or you can query with USE KEYS like so:

SELECT * FROM `travel-sample` USE KEYS "airline_10"

That form should use a direct KV fetch.


#3

Ah okay. Thanks for the info!


#4

From the syntax, I assume you can’t use wildcards in the key name, correct? Using your example, if I wanted all airline documents, I could not do something like SELECT * FROM ‘travel-sample’ USE KEYS LIKE “airline%” but I would have to use the meta().id as in SELECT meta().id FROM ‘travel-sample’ WHERE meta().id LIKE “airline%”;
Is there a better way to retrieve a list of document ids when I have to use a wildcard?


#5

Correct, a wildcard requires a WHERE clause. You should also create an index to match your WHERE clause and wildcard, and use EXPLAIN to verify that your index is being used.