Skip to content

ballad89/mgoStreamingCollection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

##MongoDB streaming collection Build Status This package is built ontop of the mongodb driver gopkg.in/mgo.v2. It adds functionality to

  • Check if a collection exist
  • Convert an uncapped collection to a capped one
  • A constructor like function, which returns a capped collection
  • Get a collection's stats
  • Query a capped collection and stream documents out of it into a channel

Installation go get github.com/ballad89/mgoStreamingCollection

Example Usage

Examples of how to use the individual functions can be seen in the test file Below is an example of how you would use it in a program

package main

import (
    "fmt"
    "gopkg.in/mgo.v2"
    "github.com/ballad89/mgoStreamingCollection"
)

func main() {
    connectUrl := "mongodb://33.33.13.45/streamingDb"

    session, err := mgo.Dial(connectUrl)

    if err != nil {
        panic(err)
    }

    session.SetSafe(&mgo.Safe{})

    defer session.Close()

    collectionName := "cappedCollection"
    collectionSize := 1024

    database := session.DB("streamingDB")

    cappedCollection, err := mgoStreamingCollection.CreateOrConvertCollection(database, collectionName, collectionSize)

    if err != nil {
        panic(err)
    }

    ch := make(chan interface{})

    go mgoStreamingCollection.TailQuery(cappedCollection.Find(nil), ch)

    for msg := range ch {
        fmt.Println(msg)
    }
}

About

package which provides an interface to streaming from a capped mongodb collection

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages