Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Collection ¶
type Collection struct {
// contains filtered or unexported fields
}
Collection represents a timeseries collection in a mongo database.
Example ¶
mgoSession = mongoDB.Session() defer mongoDB.Wipe() defer mgoSession.Close() s := NewSession(mgoSession) defer s.Close() myField := "myfield" t1 := time.Now() t2 := t1.Add(10 * time.Second) tsmgoC, _ := s.C(dbName, colName) tsmgoC.Upsert(myField, TSRecord{t1, 1}, TSRecord{t2, 2}) last, _ := tsmgoC.Last(myField) fmt.Println(last.Value) records, _ := tsmgoC.Interval(myField, t1, t2) sort.Sort(InverseChronologicalOrdering(records)) fmt.Println(records[0].Value, records[1].Value)
Output: 2 2 1
func (*Collection) Interval ¶
Interval fetches all records from timeseries mongo within the specified (closed) interval. If no records are found, an empty slice is returned.
func (*Collection) Last ¶
func (c *Collection) Last(field string) (TSRecord, error)
Last returns the last element in the timeseries, if any.
func (*Collection) Upsert ¶
func (c *Collection) Upsert(field string, val ...TSRecord) (UpsertResult, error)
Upsert bulk-inserts the given data into the timeseries database overriding the data if necessary.
type InverseChronologicalOrdering ¶
type InverseChronologicalOrdering []TSRecord
InverseChronologicalOrdering sorts TSRecords by timestamp (inverse )
func (InverseChronologicalOrdering) Len ¶
func (s InverseChronologicalOrdering) Len() int
func (InverseChronologicalOrdering) Less ¶
func (s InverseChronologicalOrdering) Less(i, j int) bool
func (InverseChronologicalOrdering) Swap ¶
func (s InverseChronologicalOrdering) Swap(i, j int)
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session represents a connection to a mongo timeseries collection.
func Dial ¶
Dial sets up a connection to the specified timeseries database specified by the passed-in URI.
func NewSession ¶
NewSession creates a new Session instance based on a copy of the passed-in instance. This returned allows the communication to the underlying timeseries mongo database.
func (*Session) C ¶
func (s *Session) C(db, coll string) (*Collection, error)
C creates a new collection with the given name.
type TSRecord ¶
type TSRecord struct { Timestamp time.Time `bson:"timestamp,omitempty"` // bson name should match timestampIndexField. Value interface{} `bson:"value,omitempty"` }
TSRecord represents a value to be added to timeseries database.
type UpsertResult ¶
UpsertResult holds the results for a timeseries upsert operation.