本文整理汇总了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)
}