I have used upsert to add document. But it returns before insertion operation completes. I have also tried to set “persist_to” but it also not working.
@daschl We have a messaging app in which we have poll type message. When one user respond to a poll, I have used upsert to insert response document.(upsert used as response can be existing) After that upsert, all other user should get real time notification about result. To calculate result, first I get all results and then prepare result from that. For that I query
SELECT * from MyApp WHERE type = 'message_response' AND messageId = 'id1';
But for first response this returns empty array. Expected result would be the document I have just inserted.
I have set indexes on type and messageId.
Same database we are using for PHP backend but in that if ‘persist_to’ set to 1 then we got expected result. Let me know if I am missing some configuration part.
It looks like you are using N1QL to retrieve the results of your poll in this instance. Due to the nature of Couchbase, our indexes are updated asynchronously from our Key/Value store itself, this means that the index may not be immediately updated after you perform your upsert. You should use the query.consistency(couchbase.N1qlQuery.Consistency) to cause your query to wait until the index is up to date.