Skip to content

Commit

Permalink
added log for store message
Browse files Browse the repository at this point in the history
Signed-off-by: jay-dee7 <[email protected]>
  • Loading branch information
jay-dee7 committed Oct 17, 2020
1 parent fac2e2d commit 1f3d90b
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions mongodb_multi_tenant.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package storage

import (
"log"

"github.com/mailhog/data"
"gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson"
"log"
)

// MongoDB represents MongoDB backed storage backend
type MultiTenantMongoDB struct {
database *mgo.Database
database *mgo.Database
}

// CreateMongoDB creates a MongoDB backed storage backend
Expand All @@ -20,19 +21,20 @@ func CreateMultiTenantMongoDB(uri, db string) *MultiTenantMongoDB {
log.Printf("Error connecting to MongoDB: %s", err)
return nil
}

return &MultiTenantMongoDB{
database: session.DB(db),
database: session.DB(db),
}
}

// Store stores a message in MongoDB and returns its storage ID
func (m *MultiTenantMongoDB) Store(msg *data.Message, tenant string) (string, error) {
err := m.database.C(tenant).Insert(m)
err := m.database.C(tenant).Insert(msg)
if err != nil {
log.Printf("Error inserting message: %s", err)
return "", err
}

return string(msg.ID), nil
}

Expand Down

0 comments on commit 1f3d90b

Please sign in to comment.