Esempio n. 1
0
func statsHandler(station storage.Station, cStatuses *mgo.Collection) storage.StationStats {
	var elevatorIds []string
	for _, stationElevator := range station.Elevators {
		elevatorIds = append(elevatorIds, stationElevator.ID)
	}
	var dbStatuses []dataStatus

	cStatuses.Find(bson.M{"elevator": bson.M{"$in": elevatorIds}}).
		Sort("lastupdate").
		All(&dbStatuses)

	events := statusesToEvents(dbStatuses)
	stats := statusesToStatistics(events)
	stats.Name = station.Name
	return stats
}
Esempio n. 2
0
File: mgo.go Progetto: Centny/dbm
func NextV(c *tmgo.Collection, id string, increase int64) (oldv int64, newv int64, err error) {
	var res = bson.M{}
	info, err := c.Find(bson.M{"_id": id}).Select(bson.M{"sequence": 1}).Apply(tmgo.Change{
		Update:    bson.M{"$inc": bson.M{"sequence": increase}},
		ReturnNew: true,
		Upsert:    true,
	}, &res)
	if err != nil {
		err = util.Err("require sequence(increase:%v) for %v fail, err:%v ", increase, id, err)
		return
	}
	if info.Updated != 1 && info.UpsertedId == nil {
		err = util.Err("require sequence(increase:%v) for %v fail, %v updated ", increase, id, info.Updated)
		return
	}
	newv = res["sequence"].(int64)
	oldv = newv - increase
	return
}
Esempio n. 3
0
File: db.go Progetto: saml/jscan
func findSubmittedData(c *mgo.Collection, ty string, skip int, limit int) ([]SubmittedData, error) {
	var a []SubmittedData
	err := c.Find(bson.M{"_type": ty}).Sort("-UpdateDate").Skip(skip).Limit(limit).All(&a)
	return a, err
}