go-bongo / bongo

Go ODM for MongoDB
MIT License
487 stars 40 forks source link

Select custom database #13

Closed ilijamt closed 7 years ago

ilijamt commented 7 years ago

Allow to select the database name for every collection. Useful if you want to allow people to switch databases. Which I needed to do easily.

Everything remains the same, with just one addition. When you create a collection, it will have a database name inside, and that collection will always point to the same database.

conf := &Config{
    ConnectionString: "localhost",
    Database:         "bongotest",
}

conn, err := Connect(conf)

    colBongoTest := conn.Collection("test")

colTestNewDBName := conn.CollectionFromDatabase("test", "NewDBName")
colTestOtherDB := conn.CollectionFromDatabase("test", "OtherDB")

References PR #12 , I've merged into master before creating the branch for this.

coveralls commented 7 years ago

Coverage Status

Coverage increased (+0.5%) to 84.706% when pulling 91ba6ba1255af21e4a1a6e3057caad81b5048894 on ilijamt:select-custom-database into 5314e13da9b18edba944ae40f46cfece482dfddf on maxwellhealth:master.

securingsincity commented 7 years ago

Thanks @ilijamt !