當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Collection.Upsert方法代碼示例

本文整理匯總了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)
}
開發者ID:johnnadratowski,項目名稱:authorizer,代碼行數:9,代碼來源:models.go

示例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})
}
開發者ID:johnnadratowski,項目名稱:authorizer,代碼行數:10,代碼來源:models.go

示例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})
}
開發者ID:johnnadratowski,項目名稱:authorizer,代碼行數:12,代碼來源:models.go

示例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
}
開發者ID:heartszhang,項目名稱:famous,代碼行數:11,代碼來源:db_feedentry.go

示例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)
	}
}
開發者ID:revence27,項目名稱:Rhema,代碼行數:13,代碼來源:transfer.go

示例6: Upsert

func Upsert(collection *mgo.Collection, query interface{}, i interface{}) bool {
	_, err := collection.Upsert(query, i)
	return Err(err)
}
開發者ID:kevinhuo88888,項目名稱:leanote,代碼行數:4,代碼來源:Mgo.go

示例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
}
開發者ID:heartszhang,項目名稱:gextract,代碼行數:4,代碼來源:db_feed.go


注:本文中的labix/org/v2/mgo.Collection.Upsert方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。