本文整理匯總了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
}