arnaucube
arnaucube/decentralized-blogging-platformPublic Self-hosted repository
decentralized-blogging-platform/mongoOperations.go
mongoOperations.goRaw
 1package main
 2
 3import (
 4	mgo "gopkg.in/mgo.v2"
 5)
 6
 7func getSession() (*mgo.Session, error) {
 8	session, err := mgo.Dial("mongodb://" + config.Mongodb.IP)
 9	if err != nil {
10		panic(err)
11	}
12	//defer session.Close()
13
14	// Optional. Switch the session to a monotonic behavior.
15	session.SetMode(mgo.Monotonic, true)
16
17	// Optional. Switch the session to a monotonic behavior.
18	session.SetMode(mgo.Monotonic, true)
19
20	return session, err
21}
22func getCollection(session *mgo.Session, collection string) *mgo.Collection {
23
24	c := session.DB(config.Mongodb.Database).C(collection)
25	return c
26}