I’m trying to get a view/livequery created that will allow me to capture documents of a certain type being created, updated and deleted. I’m wondering if I need to do something special for the deletes part, here’s what I’ve tried (which seems to work fine for creation/update)
public void CreateView(string viewName, string objectType, EventHandler<QueryChangeEventArgs> changed)
{
if (manager == null)
InitCouchBase();
var view = database.GetView(viewName);
MapDelegate map = (doc, emit) =>
{
object key;
var hasType = doc.TryGetValue("type", out key);
if (!hasType)
{
object deletvalue;
var hasdelete = doc.TryGetValue("_deleted", out deletvalue);
if (hasdelete && deletvalue.Equals(true))
{
emit(doc["_id"], null);
}
}
if (hasType && key.Equals(objectType))
{
emit(doc["_id"], null);
}
};
view.SetMap(map, "2.0");
var query = view.CreateQuery().ToLiveQuery();
query.Changed += changed;
query.Start();
}