func CreateNewMongoGraph(addr string, options graph.Options) bool { conn, err := mgo.Dial(addr) if err != nil { glog.Fatal("Error connecting: ", err) return false } conn.SetSafe(&mgo.Safe{}) dbName := DefaultDBName if val, ok := options.StringKey("database_name"); ok { dbName = val } db := conn.DB(dbName) indexOpts := mgo.Index{ Key: []string{"Sub"}, Unique: false, DropDups: false, Background: true, Sparse: true, } db.C("triples").EnsureIndex(indexOpts) indexOpts.Key = []string{"Pred"} db.C("triples").EnsureIndex(indexOpts) indexOpts.Key = []string{"Obj"} db.C("triples").EnsureIndex(indexOpts) indexOpts.Key = []string{"Provenance"} db.C("triples").EnsureIndex(indexOpts) return true }
func _ensureDbIndexes(session *mgo.Session) { sessions := session.DB(_cfg.Database).C(SESSIONS_COLLECTION) expireSessionsIndex := mgo.Index{} //TODO: should read from the sessions config //or be invoked from the bootstrapper expireSessionsIndex.ExpireAfter = 1 * time.Hour expireSessionsIndex.Key = []string{"expiry"} sessions.EnsureIndex(expireSessionsIndex) }
// Index creates the default indeces for the graph. func (m *Mongo) Index(gid string, background bool) error { m.Session.ResetIndexCache() sessionCopy := m.Session.Copy() defer sessionCopy.Close() col := sessionCopy.DB(m.DBName).C(gid) cInfo := &mgo.CollectionInfo{DisableIdIndex: true} err := col.Create(cInfo) if err != nil { log.Error(err) } /* // TODO figure out the magic of mongo indexes index := mgo.Index{ Key: []string{"g", "s", "p", "o"}, Background: false, Sparse: true, Unique: true, DropDups: true, } err := col.EnsureIndex(index) return err */ index := mgo.Index{ Key: []string{"g", "s"}, Background: background, Sparse: true, } err = col.EnsureIndex(index) if err != nil { log.Error(err) //return err } log.V(2).Infof("%+v", index) index.Key = []string{"g", "o"} err = col.EnsureIndex(index) if err != nil { log.Error(err) //return err } log.V(2).Infof("%+v", index) index.Key = []string{"g", "p"} err = col.EnsureIndex(index) if err != nil { log.Error(err) //return err } log.V(2).Infof("%+v", index) index.Key = []string{"g", "s", "p"} err = col.EnsureIndex(index) if err != nil { log.Error(err) //return err } log.V(2).Infof("%+v", index) index.Key = []string{"g", "s", "o"} err = col.EnsureIndex(index) if err != nil { log.Error(err) //return err } log.V(2).Infof("%+v", index) index.Key = []string{"g", "p", "o"} err = col.EnsureIndex(index) if err != nil { log.Error(err) //return err } log.V(2).Infof("%+v", index) index.Key = []string{"g", "s", "p", "o"} index.Unique = true index.DropDups = true err = col.EnsureIndex(index) if err != nil { log.Error(err) //return err } log.V(2).Infof("%+v", index) return nil }