To give you a speedier response, view queries run against “stale” indexes by default. Couchbase then re-runs the view to refresh the index after it gives you the response.
At this point, Couchbase runs the view again to update the index. The index still shows 5.
irb(main):009:0> TestDoc.create(id: "testing123")
=> #<TestDoc id: testing123, created_at: 2015-03-23 09:14:47 -0400, type: "txn", updated_at: 2015-03-23 09:14:47 -0400>
Couchbase does not re-run the view on insertion.
### I can wait 5 minutes here and it does not make a difference
You can configure Couchbase to automatically update production indexes. Auto updates don’t work on development views, though.
At this point, Couchbase now re-runs the view to rebuild the index … and your new document is now in the index as you see when you re-run your query below.
You can get around this by specifying stale=false in your query. That’ll make Couchbase re-run the view before it returns the result, and of course there’ll be a performance impact.