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


Golang bson.ObjectId函数代码示例

本文整理汇总了Golang中labix/org/v2/mgo/bson.ObjectId函数的典型用法代码示例。如果您正苦于以下问题:Golang ObjectId函数的具体用法?Golang ObjectId怎么用?Golang ObjectId使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: traverseMention

func traverseMention() {
	// retrieve one mention, evaluate, and write it back to the database
	session, err := database() // establish session with database
	if err != nil {
		panic(err)
	}
	defer session.Close()
	d := session.DB("batcave2").C("mention")

	var mention Mention

	err = d.Find(bson.M{"Sentiment": nil}).One(&mention)
	if err != nil {
		fmt.Println("Find error: Mentions without sentiment", err)
		time.Sleep(10 * time.Second) // wait for new mentions to show up in database
		return
	}

	id := bson.ObjectId(mention.Id)

	fmt.Println("Mention: ", mention) // debugging
	mention.Sentiment = parseMention(mention.Text)
	fmt.Println("Sentiment: ", mention.Sentiment) // debugging

	err = d.UpdateId(id, bson.M{"$addToSet": bson.M{"Sentiment": mention.Sentiment}})

	if err != nil {
		fmt.Println("Update: ", err)
	}
}
开发者ID:eliobotogoske,项目名称:facebookcrawler-2,代码行数:30,代码来源:nlp.go

示例2: decodeId

func decodeId(s string) (bson.ObjectId, error) {
	val, err := base64.URLEncoding.DecodeString(s)
	if err != nil {
		panic("Can't decode id: " + err.Error())
	}
	return bson.ObjectId(val), nil
}
开发者ID:Laller,项目名称:nocrud,代码行数:7,代码来源:set.go

示例3: SaveModel

// Save the DataModel to DataStore
func SaveModel(mgo_db string, m DataModel, conn *mgo.Session) (err error) {
	if conn == nil {
		conn, err = MgoConnGet(mgo_db)
		if err != nil {
			return
		}
		defer conn.Close()
	}
	if conn != nil {
		bsonMid := m.MidGet()
		c := conn.DB(mgo_db).C(m.Type())
		//Debug("SAVING ", mgo_db, " type=", m.Type(), " Mid=", bsonMid)
		if len(bsonMid) < 5 {
			m.MidSet(bson.NewObjectId())
			if err = c.Insert(m); err != nil {
				Log(ERROR, "MGOU ERROR on insert ", err, " TYPE=", m.Type(), " ", m.MidGet())
			} else {
				//Log(DEBUG, "successfully inserted!!!!!!  ", m.MidGet(), " oid=", m.OidGet())
			}
		} else {
			// YOU MUST NOT SEND Mid  "_id" to Mongo
			mid := m.MidGet()
			m.MidSet("") // omitempty means it doesn't get sent
			if err = c.Update(bson.M{"_id": bson.ObjectId(bsonMid)}, m); err != nil {
				Log(ERROR, "MGOU ERROR on update ", err, " ", bsonMid, " MID=?", m.MidGet())
			}
			m.MidSet(mid)
		}
	} else {
		Log(ERROR, "MGOU Nil connection")
		return errors.New("no db connection")
	}
	return
}
开发者ID:araddon,项目名称:mgou,代码行数:35,代码来源:store.go

示例4: readField1

func (p *UserGroup) readField1(iprot thrift.TProtocol) error {
	if v, err := iprot.ReadString(); err != nil {
		return fmt.Errorf("error reading field 1: %s", err)
	} else {
		p.ID = bson.ObjectId(v)
	}
	return nil
}
开发者ID:qiandashuai,项目名称:xuanwu,代码行数:8,代码来源:gen_usergroup.go

示例5: OneDocumentID

func (self *query_base) OneDocumentID() (id bson.ObjectId, err error) {
	q, err := self.thisQuery.mongoQuery()
	if err != nil {
		return bson.ObjectId(""), err
	}
	var doc DocumentBase
	err = q.One(&doc)
	return doc.ID, err
}
开发者ID:mda747,项目名称:go-start,代码行数:9,代码来源:query_base.go

示例6: ToObjectId

func ToObjectId(id string) (bid bson.ObjectId, err error) {
	var d []byte
	d, err = hex.DecodeString(id)
	if err != nil || len(d) != 12 {
		err = fmt.Errorf("Invalid input to ObjectIdHex: %q", id)
		return
	}
	bid = bson.ObjectId(d)
	return
}
开发者ID:kobeld,项目名称:duoerl,代码行数:10,代码来源:strings.go

示例7: String

func (ca *ConnectedAgent) String(m *model.Model) string {
	if ca.station != nil {
		if station, err := m.FindStationById(bson.ObjectId(*ca.station)); err == nil {
			return fmt.Sprintf("Agent %s in station %s", ca.login, station.Name)
		} else {
			return fmt.Sprintf("Agent %s in unknown station %s", ca.login, *ca.station)
		}
	} else {
		return fmt.Sprintf("Agent %s outside a station", ca.login)
	}
}
开发者ID:JohnAtWassa,项目名称:hackcessangels,代码行数:11,代码来源:connected_agent.go

示例8: SetStringID

func (self *Ref) SetStringID(str string) error {
	switch len(str) {
	case 0, 12:
		self.ID = bson.ObjectId(str)
	case 24:
		self.ID = bson.ObjectIdHex(str)
	default:
		return errs.Format("Invalid string for bson.ObjectId: '%s'", str)
	}
	return nil
}
开发者ID:prinsmike,项目名称:go-start,代码行数:11,代码来源:ref.go

示例9: ObjectId

func (op *Operation) ObjectId() (bson.ObjectId, error) {
	var object bson.M

	switch op.Op {
	case Update:
		object = op.UpdateObject
	default:
		object = op.Object
	}

	id, ok := object["_id"]
	if !ok {
		return bson.ObjectId(""), OperationError{"_id does not exist in object", op}
	}

	bid, ok := id.(bson.ObjectId)
	if !ok {
		return bson.ObjectId(""), OperationError{"Could not find a bson objectid", op}
	}
	return bid, nil
}
开发者ID:ehogberg,项目名称:cryriver,代码行数:21,代码来源:operation.go

示例10: Get

// Get retriives task by id
func (t *Task) Get(id string) (*TaskRow, error) {

	var tr TaskRow
	err := t.coll.FindId(bson.ObjectId(id)).One(&tr) // .Sort("created").
	if err != nil {
		if err == mgo.ErrNotFound {
			return nil, ErrNotFound
		}
		return nil, err
	}
	return &tr, nil
}
开发者ID:gophergala2016,项目名称:gobench,代码行数:13,代码来源:task.go

示例11: main

func main() {
	c, m := ConnectToMongoAndGetCollection()
	unprocessedSessions := GetAllRelevantSessions(c)
	r := lib.ConnectToRedis()
	var results []GameSessionResult
	for _, session := range unprocessedSessions {
		results = append(results, getWinsAndLosses(session, r))
	}

	increasingWins := func(r1, r2 *GameSessionResult) bool {
		return (r1.Wins - r1.Losses) > (r2.Wins - r2.Losses)
	}
	OrderedBy(increasingWins).Sort(results)
	for i, result := range results {
		results[i] = result.getCreatorName(c)
	}
	for i, result := range results {
		results[i] = result.getSessionDetails(m)
	}
	var ogres []GameSessionResult
	var humans []GameSessionResult
	for _, result := range results {
		if result.Session.Team == "ogres" {
			ogres = append(ogres, result)
		} else {
			humans = append(humans, result)
		}
	}

	fmt.Println("Top ogres")
	for _, result := range ogres {
		fmt.Printf("%d,%s,%s,%s,%d,%d,%d\n", result.PreliminaryRank, bson.ObjectId(result.Session.ID), result.CreatorName, result.Email, result.Playtime, result.Wins, result.Losses)
	}
	fmt.Println("Top humans")
	for _, result := range humans {
		fmt.Printf("%d,%s,%s,%s,%d,%d,%d\n", result.PreliminaryRank, bson.ObjectId(result.Session.ID), result.CreatorName, result.Email, result.Playtime, result.Wins, result.Losses)
	}

}
开发者ID:schmatz,项目名称:coco-verify,代码行数:39,代码来源:results.go

示例12: GetAndDelete

// GetAndDelete returns task and deletes it if found. If not found returns nil, model.ErrNotFound
func (t *Task) GetAndDelete(id string) (*TaskRow, error) {

	var tr TaskRow
	_, err := t.coll.FindId(bson.ObjectId(id)).Apply(mgo.Change{Remove: true, ReturnNew: false}, &tr)
	if err != nil {
		if err == mgo.ErrNotFound {
			return nil, ErrNotFound
		}
		return nil, err
	}

	return &tr, nil
}
开发者ID:gophergala2016,项目名称:gobench,代码行数:14,代码来源:task.go

示例13: Init

func (application *Application) Init(filename *string) {
	gob.Register(bson.ObjectId(""))

	data, err := ioutil.ReadFile(*filename)

	if err != nil {
		glog.Fatalf("Can't read configuration file: %s", err)
		panic(err)
	}

	application.Configuration = &Configuration{}

	err = json.Unmarshal(data, &application.Configuration)

	if err != nil {
		glog.Fatalf("Can't parse configuration file: %s", err)
		panic(err)
	}

	application.Store = sessions.NewCookieStore([]byte(application.Configuration.Secret))
}
开发者ID:resal81,项目名称:defaultproject,代码行数:21,代码来源:core.go

示例14: UpdateFirewallStatus

//Saves Firewall Request to MongoDB
func UpdateFirewallStatus(id string, statusUpdate string) {
	//var pass string
	log.Printf("Updating status to:\t%s for firewall:\t%s\n\n", statusUpdate, id)
	// TODO - Append Status Variable to fwreq with Current Queue
	session, err := mgo.Dial("localhost")
	if err != nil {
		log.Println(err)
	}
	defer session.Close()
	requestCollection := session.DB("firewallapp").C("fwreq")
	hexId, hexErr := hex.DecodeString(id)
	if hexErr != nil {
		log.Printf("\n\nERROR:\t%s\n\n", hexErr)
	}
	updateId := bson.M{"_id": bson.ObjectId(hexId)}
	update := bson.M{"$set": bson.M{"status": statusUpdate}}
	updateErr := requestCollection.Update(updateId, update)
	if updateErr != nil {
		log.Printf("Can't update document %v\n", updateErr)
	}
}
开发者ID:postfix,项目名称:stoplight,代码行数:22,代码来源:firewall.go

示例15: tarjanSort

func tarjanSort(successors map[bson.ObjectId][]bson.ObjectId) [][]bson.ObjectId {
	// http://en.wikipedia.org/wiki/Tarjan%27s_strongly_connected_components_algorithm
	data := &tarjanData{
		successors: successors,
		nodes:      make([]tarjanNode, 0, len(successors)),
		index:      make(map[bson.ObjectId]int, len(successors)),
	}

	// Sort all nodes to stabilize the logic.
	var all []string
	for id := range successors {
		all = append(all, string(id))
	}
	sort.Strings(all)
	for _, strid := range all {
		id := bson.ObjectId(strid)
		if _, seen := data.index[id]; !seen {
			data.strongConnect(id)
		}
	}
	return data.output
}
开发者ID:davidsoloman,项目名称:beats,代码行数:22,代码来源:tarjan.go


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