// Cleanup removes all documents that were previously marked for removal, if // any such exist. It should be called periodically by at least one element // of the system. func (st *State) Cleanup() error { doc := cleanupDoc{} iter := st.cleanups.Find(nil).Iter() for iter.Next(&doc) { var c *mgo.Collection var sel interface{} switch doc.Kind { case "settings": c = st.settings sel = D{{"_id", D{{"$regex", "^" + doc.Prefix}}}} default: log.Printf("state: WARNING: ignoring unknown cleanup kind %q", doc.Kind) continue } if count, err := c.Find(sel).Count(); err != nil { return fmt.Errorf("cannot detect cleanup targets: %v", err) } else if count != 0 { // Documents marked for cleanup are not otherwise referenced in the // system, and will not be under watch, and are therefore safe to // delete directly. if _, err := c.RemoveAll(sel); err != nil { return fmt.Errorf("cannot remove documents marked for cleanup: %v", err) } } ops := []txn.Op{{ C: st.cleanups.Name, Id: doc.Id, Remove: true, }} if err := st.runner.Run(ops, "", nil); err != nil { return fmt.Errorf("cannot remove empty cleanup document: %v", err) } } if err := iter.Err(); err != nil { return fmt.Errorf("cannot read cleanup document: %v", err) } return nil }
func DeleteAll(collection *mgo.Collection, q interface{}) bool { _, err := collection.RemoveAll(q) return Err(err) }
func DeleteAllByIdAndUserId2(collection *mgo.Collection, id, userId bson.ObjectId) bool { _, err := collection.RemoveAll(GetIdAndUserIdBsonQ(id, userId)) return Err(err) }
// 删除所有 func DeleteAllByIdAndUserId(collection *mgo.Collection, id, userId string) bool { _, err := collection.RemoveAll(GetIdAndUserIdQ(id, userId)) return Err(err) }