当前位置: 首页>>代码示例>>Golang>>正文


Golang Collection.Update方法代码示例

本文整理汇总了Golang中labix/org/v2/mgo.Collection.Update方法的典型用法代码示例。如果您正苦于以下问题:Golang Collection.Update方法的具体用法?Golang Collection.Update怎么用?Golang Collection.Update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在labix/org/v2/mgo.Collection的用法示例。


在下文中一共展示了Collection.Update方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: confirmChecksum

func (a *Asset) confirmChecksum(coll *mgo.Collection, finished chan int) {
	defer func() { finished <- 1 }()

	fmt.Printf("Checking %s\n", a.Url)

	activeRequests <- 1
	resp, err := http.Get(a.Url)
	<-activeRequests

	if err != nil {
		fmt.Printf("Got HTTP Error for %s.  Error: %v\n", a.Url, err)
		return
	}

	newHasher := md5.New()
	io.Copy(newHasher, resp.Body)
	newHash := hex.EncodeToString(newHasher.Sum(nil))

	if newHash != a.Checksum {
		fmt.Printf("Hashes did not match: %s != %s\n", newHash, a.Checksum)
		a.Checksum = newHash
		err = coll.Update(bson.M{"_id": a.Id}, a)
		if err != nil {
			fmt.Printf("Error updating hash, got error %v\n", err)
		}
	} else {
		fmt.Printf("Hashes Matched!\n")
	}

}
开发者ID:josephwegner,项目名称:canary,代码行数:30,代码来源:main.go

示例2: update

// Update Account into Mongo
func update(u Account, s *mgo.Collection) {
	colQuerier := bson.M{"name": u.Name}
	change := bson.M{"$set": bson.M{"email": u.Email, "phone": u.Phone, "password": u.Password, "type": u.Type}}
	err := s.Update(colQuerier, change)
	if err != nil {
		panic(err)
	}
}
开发者ID:rcijov,项目名称:go,代码行数:9,代码来源:account.go

示例3: checkSpecialActionVerbs

func checkSpecialActionVerbs(w http.ResponseWriter, statementsC *mgo.Collection, statement Statement) int {

	//voiding
	if statement.Verb.Id == "http://adlnet.gov/expapi/verbs/voided" {

		// check has statementId to void
		if statement.Object.ObjectType != "StatementRef" {
			// fmt.Fprint(w, "StatementRef")
			return http.StatusBadRequest
		}

		if statement.Object.Id == "" {
			// fmt.Fprint(w, "Object.Id")
			return http.StatusBadRequest
		}

		// find if statement to be voided exists
		var result Statement
		err := statementsC.Find(bson.M{"id": statement.Object.Id}).One(&result)
		if err != nil {
			// fmt.Fprint(w, "not found refrence"+statement.Object.Id)
			// fmt.Fprint(w, err)
			return http.StatusBadRequest
		}

		// if statement hasn't been voided do so
		if result.Void != true {
			err = statementsC.Update(bson.M{"id": result.Id}, bson.M{"$set": bson.M{"void": true}})
			if err != nil {
				// fmt.Fprint(w, "cant update")
				//fmt.Fprint(w, err)
				return http.StatusBadRequest
			}
		}
	} else if statement.Object.ObjectType == "StatementRef" { //check if statement's ref exists (might be moved to validate)
		if statement.Object.Id == "" {
			//fmt.Fprint(w, "Object.Id")
			return http.StatusBadRequest
		}

		// find if statement to be voided exists
		var result Statement
		err := statementsC.Find(bson.M{"id": statement.Object.Id}).One(&result)
		if err != nil {
			//fmt.Fprint(w, "not found refrence")
			return http.StatusBadRequest
		}
	}
	return 0
}
开发者ID:DalianDragon,项目名称:GO_LRS,代码行数:50,代码来源:LRSapi.go

示例4: savePost

func savePost(collection *mgo.Collection, shortID int, title, subtitle, slugString, category, body string) (post models.Post) {
	// Update Dataz
	err := collection.Update(bson.M{"shortid": shortID}, bson.M{
		"$set": bson.M{
			"title":    title,
			"subtitle": subtitle,
			"category": category,
			"slug":     slugString,
			"body":     body,
		},
	})

	if err != nil {
		panic(err)
	}

	result := models.Post{}
	collection.Find(bson.M{"title": title}).One(&result)
	return result
}
开发者ID:relvinhas,项目名称:ironzebra,代码行数:20,代码来源:admin.go

示例5: Update

func Update(col *mgo.Collection, key int, newname string) error {
	return col.Update(bson.M{keyfield: key}, bson.M{namefield: newname})
}
开发者ID:voutasaurus,项目名称:metamark,代码行数:3,代码来源:database_test.go

示例6: ExecUpdate

func (executor *OpsExecutor) ExecUpdate(
	content Document, coll *mgo.Collection) error {
	return coll.Update(content["query"], content["updateobj"])
}
开发者ID:rzh,项目名称:flashback,代码行数:4,代码来源:ops_executor.go

示例7: UpdateByIdAndUserId2

func UpdateByIdAndUserId2(collection *mgo.Collection, id, userId bson.ObjectId, i interface{}) bool {
	err := collection.Update(GetIdAndUserIdBsonQ(id, userId), i)
	return Err(err)
}
开发者ID:kevinhuo88888,项目名称:leanote,代码行数:4,代码来源:Mgo.go

示例8: UpdateByIdAndUserId

func UpdateByIdAndUserId(collection *mgo.Collection, id, userId string, i interface{}) bool {
	err := collection.Update(GetIdAndUserIdQ(id, userId), i)
	return Err(err)
}
开发者ID:kevinhuo88888,项目名称:leanote,代码行数:4,代码来源:Mgo.go

示例9: Update

// 适合一条记录全部更新
func Update(collection *mgo.Collection, query interface{}, i interface{}) bool {
	err := collection.Update(query, i)
	return Err(err)
}
开发者ID:kevinhuo88888,项目名称:leanote,代码行数:5,代码来源:Mgo.go


注:本文中的labix/org/v2/mgo.Collection.Update方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。