Enjoying the Process
May 13, 2022Timeline view in VS Code
June 10, 2022Recently we discovered an issue when entering data where the API would save the data and immediately refetch the data and would return stale data. We are using a NodeJS API with GraphQL and using Couchbase as our data store. The reason we were seeing these results is that by default, N1QL queries do not ensure all documents have been indexed before returning the results.
Add query options
To ensure the data is up to date when retrieving the second query that depends on results of the initial query, add the following to your query options: {scanConsistency: ‘request_plus’}.
That’s it! This will now ensure that all documents are indexed before returning the query results. While you are trading off a little bit of performance, you can now expect consistency and the expected data