diff --git a/mongo/database.go b/mongo/database.go index e6cd8cb6802bf545df3665bc1b4abd30ac55f25e..7e720e80dae2cdecf29e69d808b9ac78fa95e62c 100644 --- a/mongo/database.go +++ b/mongo/database.go @@ -1,5 +1,5 @@ /* - Copyright (c) 2012-2013 JosĂŠ Carlos Nieto, https://menteslibres.net/xiam + Copyright (c) 2012-2014 JosĂŠ Carlos Nieto, https://menteslibres.net/xiam Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -27,6 +27,7 @@ import ( "fmt" "labix.org/v2/mgo" "net/url" + "strings" "time" "upper.io/db" ) @@ -136,18 +137,24 @@ func (self *Source) Drop() error { return err } -// Returns a list of all tables within the currently active database. -func (self *Source) Collections() ([]string, error) { - cols := []string{} - rawcols, err := self.database.CollectionNames() - if err != nil { +// Returns a slice of non-system collection names within the active +// database. +func (self *Source) Collections() (cols []string, err error) { + var rawcols []string + var col string + + if rawcols, err = self.database.CollectionNames(); err != nil { return nil, err } - for _, col := range rawcols { - if col != "system.indexes" { + + cols = make([]string, 0, len(rawcols)) + + for _, col = range rawcols { + if strings.HasPrefix(col, "system.") == false { cols = append(cols, col) } } + return cols, nil } diff --git a/mongo/database_test.go b/mongo/database_test.go index f4c8edbcd46e16c3897f1d59f239ca5b95636954..c9a567e756adadbd2cc148bdf3392134b9d2e825 100644 --- a/mongo/database_test.go +++ b/mongo/database_test.go @@ -1,5 +1,5 @@ /* - Copyright (c) 2012-2013 JosĂŠ Carlos Nieto, https://menteslibres.net/xiam + Copyright (c) 2012-2014 JosĂŠ Carlos Nieto, https://menteslibres.net/xiam Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -20,10 +20,7 @@ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ - -/* - Tests for the mongo wrapper. -*/ +// Tests for the mongodb adapter. package mongo import (