Hi,
I’m hoping I’m doing something really dumb here.
I have a C# program (currently on Mac using Xamarin).
I use a local couchbase mobile DB, connecting to Sync Gateway on ubuntu.
Weird thing is that every time I change any record locally, I get all my LiveQueries ‘changed’ events firing.
For example: I have a singleton user record (‘type’ field == “User”). If I post a change to that using:
document = database.GetDocument(id);
document.PutProperties(properties)
then all of my 3 live queries will fire - yet they are monitoring completely different data.
Here’s an example of one of the live queries:
I have a number of book objects (‘type’ == “Book”) - each of which contains a number of sections ('type == “Section”).
I have a live query watching the book, and a live query watching the current list of sections.
The view I use fetch sections for a given book is as follows. It looks for objects of type Section, and outputs their book_id for the index.
view = database.GetView("SectionsByBook");
view.SetMap((doc, emit) =>
{
if (doc.ContainsKey("type") && (string)doc["type"] == "Section")
emit((string)doc["book_id"], doc);
}, "2");
Now I can create a live query:
var query = database.GetView("SectionsByBook").CreateQuery();
query.StartKey = book_id;
query.EndKey = book_id;
var liveQuery = query.ToLiveQuery();
Lastly I hook up the update function.
liveQuery.Changed += UpdateSections;
liveQuery.Start();
In the function “UpdateSections” - I can see the correct list of sections being available.
The problem is that UpdateSections is called to any change to any record in the database,
such as a change to the User record. It should only be called on a change to the current list
of sections for the current book.
Any thoughts on what I’m doing wrong?
Many thanks.
Paul.