func (c *C) Update(a iface.Filter, data map[string]interface{}) error { files_map, has := data["_files"].(map[string]interface{}) upd := map[string]interface{}{ "$set": data, } if has { ids, err := a.Ids() if err != nil { return err } err = c.moveFiles(a.Subject(), ids[0].Hex(), files_map) if err != nil { return err } delete(data, "_files") upd["$addToSet"] = eachIfNeeded(fileheadersToFilenames(files_map)) } err := a.Update(upd) if err != nil { return err } if c.Ev != nil { c.Ev.Fire("Updated", a) c.Ev.Fire(a.Subject()+"Updated", a) } return nil }
func (f *Filter) Reduce(a ...iface.Filter) (iface.Filter, error) { l := len(a) if l == 0 { return &Filter{}, fmt.Errorf("Nothing to reduce.") } var prev iface.Filter prev = f for _, v := range a { ids, err := prev.Ids() if err != nil { return &Filter{}, err } v.AddParents("_"+prev.Subject(), ids) prev = v } return prev, nil }