Ottoman find or findByX gives strange results

I’m having an issue whereby I have a document in Couchbase. I perform a find({property=‘blah’}) or findByProperty(‘blah’) search via node/Couchbase/Ottoman and I get the one result, no problem. I then wait a while, lets say 10 minutes then perform the same query and this time I get no results. I then perform the query again and it correctly sees the one entry. I can also get the same effect by manually adding or deleting documents via Couchbase directly then performing the query via node. It takes two attempts to get the correct result.

I’m using the following versions from my packages.json:

couchbase: “~2.2.4”,
ottoman: “~1.0.4”

This is making me very nervous to use Ottoman in a production environment. Any help would be greatly appreciated.

Cheers

Hey @f.reynolds,
It is likely that you are performing the queries without specifying any consistency requirement. This is telling Couchbase Server that you do not care about the consistency of the results of your query. Try specifying a consistency level that is higher. This is done in Ottoman.js by specifying Ottoman.SearchConsistency.Consistency.XXXXX for the ‘consistency’ option of a find or in the Node.js SDK by using N1qlQuery.consistency with couchnode.N1qlQuery.Consistency.XXXXX.
Cheers, Brett

Hi @Brett19,

Thanks for your answer, I’m just picking this up now after the holidays.
This was a real problem for us so I’m grateful that there’s a solution.
I do have another question in that can you set this on a per request
basis such as for an index or for a specific use of a findByXXX or am I
missing the point?

var Furniture = ottoman.model('Furniture', { name: 'string' }, { index: { findByName: { by: 'name', consistency: 2 // is this correct ? ? ? } } });

Or this:

Furniture.findByName('table', { consistency: 2 // is this possible ? ? ? }, function(err, tables) { if (err) return console.error(err); console.log(tables); })

Cheers,

Fabrice

Hey Fabrice,

Both of those should work. You can define it on the index itself, but are able to override that on each call as well.

Cheers, Brett

Thanks Brett,

Adding the consistency to the index did the trick however I didn’t get much luck adding it into the findBy or find options which is why I was confused.

Cheers,

Fabrice