// 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 }