当前位置: 首页>>代码示例>>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;未经允许,请勿转载。