本文整理汇总了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")
}
}
示例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)
}
}
示例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
}
示例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
}
示例5: Update
func Update(col *mgo.Collection, key int, newname string) error {
return col.Update(bson.M{keyfield: key}, bson.M{namefield: newname})
}
示例6: ExecUpdate
func (executor *OpsExecutor) ExecUpdate(
content Document, coll *mgo.Collection) error {
return coll.Update(content["query"], content["updateobj"])
}
示例7: UpdateByIdAndUserId2
func UpdateByIdAndUserId2(collection *mgo.Collection, id, userId bson.ObjectId, i interface{}) bool {
err := collection.Update(GetIdAndUserIdBsonQ(id, userId), i)
return Err(err)
}
示例8: UpdateByIdAndUserId
func UpdateByIdAndUserId(collection *mgo.Collection, id, userId string, i interface{}) bool {
err := collection.Update(GetIdAndUserIdQ(id, userId), i)
return Err(err)
}
示例9: Update
// 适合一条记录全部更新
func Update(collection *mgo.Collection, query interface{}, i interface{}) bool {
err := collection.Update(query, i)
return Err(err)
}