https://github.com/danielfireman/tsmgo
#golang library which makes intuitive to work with time-series data in Mongo DB.
https://github.com/danielfireman/tsmgo
golang-library golang-package mongodb time-series
Last synced: about 2 months ago
JSON representation
#golang library which makes intuitive to work with time-series data in Mongo DB.
- Host: GitHub
- URL: https://github.com/danielfireman/tsmgo
- Owner: danielfireman
- License: mit
- Created: 2018-08-21T17:54:55.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-08-27T16:36:56.000Z (almost 8 years ago)
- Last Synced: 2025-04-25T13:03:46.016Z (about 1 year ago)
- Topics: golang-library, golang-package, mongodb, time-series
- Language: Go
- Homepage:
- Size: 459 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.org/danielfireman/tsmgo) [](https://codecov.io/gh/danielfireman/tsmgo/branch/master/graph/badge.svg) [](https://goreportcard.com/report/github.com/danielfireman/tsmgo) [](https://godoc.org/github.com/danielfireman/tsmgo)
# tsmgo
#golang library which makes intuitive to work with time-series data in Mongo DB.
The schema design is inspired by [this article](https://www.mongodb.com/blog/post/schema-design-for-time-series-data-in-mongodb).
# Using tsmgo
```go
import "github.com/danielfireman/tsmgo"
```
**New tsmgo.Session**
```go
tsSession := tsmgo.NewSession(mgoSession)
c, _ := tsSession.C(dbName, colName)
```
or
```go
tsSession, err := tsmgo.Dial(mongoURL)
c, _ := tsSession.C(dbName, colName)
```
Where mgoSession is a [github.com/globalsign/mgo#Session](https://godoc.org/github.com/globalsign/mgo#Session).
**Adding timeseries records**
```go
c.Upsert(myField, TSRecord{time.Now(), 1})
```
or
```go
t1 := time.Now()
t2 := t1.Add(10 * time.Second)
c.Upsert(myField, TSRecord{t1, 1}, TSRecord{t2, 2})
```
**Retrieving last item inserted**
```go
last, _ := tsmgoC.Last(myField)
```
**Retrieving all itens inserted in the last 24 hours**
```go
now := time.Now()
items, _ := tsmgoC.Interval(myField, now.Add(-24*time.Hour), now)
```
# Contributing
1. Install [dep](https://github.com/golang/dep/blob/master/docs/installation.md)
1. `dep ensure`
1. `go test -v`
Either if you're fixing a bug or adding a new feature, please add a test to cover it.
If all tests passes, please you're ready to send the PR.