本文整理汇总了Golang中labix/org/v2/mgo.Collection.Upsert方法的典型用法代码示例。如果您正苦于以下问题:Golang Collection.Upsert方法的具体用法?Golang Collection.Upsert怎么用?Golang Collection.Upsert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类labix/org/v2/mgo.Collection
的用法示例。
在下文中一共展示了Collection.Upsert方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Set
// Sets the privileges to a whole new ACL
func (a ACL) Set(c *mgo.Collection, service string, object string, key string, user string, privileges map[string]interface{}) (*mgo.ChangeInfo, error) {
selector := bson.M{"service": service, "object": object, "key": key, "user": user}
update := copyMap(selector)
update["privileges"] = privileges
log.Finest("Setting Privilege: %s", update)
return c.Upsert(selector, update)
}
示例2: Revoke
// Revokes the privileges from the existing ACL
func (a ACL) Revoke(c *mgo.Collection, service string, object string, key string, user string, privileges []string) (*mgo.ChangeInfo, error) {
selector := bson.M{"service": service, "object": object, "key": key, "user": user}
toRevoke := map[string]interface{}{}
for _, privilege := range privileges {
toRevoke["privileges."+privilege] = ""
}
log.Finest("Revoking Privilege: %s, %s", selector, toRevoke)
return c.Upsert(selector, bson.M{"$unset": toRevoke})
}
示例3: Deny
// Denies the privileges from the existing ACL
func (a ACL) Deny(c *mgo.Collection, service string, object string, key string, user string, privileges []string) (*mgo.ChangeInfo, error) {
selector := bson.M{"service": service, "object": object, "key": key, "user": user}
update := copyMap(selector)
for _, privilege := range privileges {
update["privileges."+privilege] = "deny"
}
log.Finest("Denying Privilege: %s", update)
return c.Upsert(selector, bson.M{"$set": update})
}
示例4: insert_entry
func insert_entry(coll *mgo.Collection, entry ReadEntry) (interface{}, error) {
xe := struct {
ReadEntry `bson:",inline"`
TTL time.Time `bson:"ttl"`
}{entry, time.Now()}
ci, err := coll.Upsert(bson.M{"uri": entry.Uri}, bson.M{"$setOnInsert": &xe})
if ci == nil {
return nil, err
}
return ci.UpsertedId, err
}
示例5: idempotentRecordVerse
func idempotentRecordVerse(cid interface{}, verse Verse, col *mgo.Collection) {
_, e := col.Upsert(bson.M{
"chapter": cid,
"position": verse.Position,
}, bson.M{
"chapter": cid,
"position": verse.Position,
"rhema": verse.Rhema,
})
if e != nil {
panic(e)
}
}
示例6: Upsert
func Upsert(collection *mgo.Collection, query interface{}, i interface{}) bool {
_, err := collection.Upsert(query, i)
return Err(err)
}
示例7: insert_entry
func insert_entry(coll *mgo.Collection, entry Entry) (interface{}, error) {
ci, err := coll.Upsert(bson.M{"link": entry.Link}, bson.M{"$setOnInsert": &entry})
return ci.UpsertedId, err
}