本文整理匯總了Golang中labix/org/v2/mgo.Collection.RemoveAll方法的典型用法代碼示例。如果您正苦於以下問題:Golang Collection.RemoveAll方法的具體用法?Golang Collection.RemoveAll怎麽用?Golang Collection.RemoveAll使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類labix/org/v2/mgo.Collection
的用法示例。
在下文中一共展示了Collection.RemoveAll方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Cleanup
// 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
}
示例2: DeleteAll
func DeleteAll(collection *mgo.Collection, q interface{}) bool {
_, err := collection.RemoveAll(q)
return Err(err)
}
示例3: DeleteAllByIdAndUserId2
func DeleteAllByIdAndUserId2(collection *mgo.Collection, id, userId bson.ObjectId) bool {
_, err := collection.RemoveAll(GetIdAndUserIdBsonQ(id, userId))
return Err(err)
}
示例4: DeleteAllByIdAndUserId
// 刪除所有
func DeleteAllByIdAndUserId(collection *mgo.Collection, id, userId string) bool {
_, err := collection.RemoveAll(GetIdAndUserIdQ(id, userId))
return Err(err)
}