// Wrapper to get hold of a factoid collection handle func Collection(dbh *db.Database, l logging.Logger) *FactoidCollection { fc := &FactoidCollection{ Collection: dbh.C(COLLECTION), seen: make(map[string][]bson.ObjectId), l: l, } err := fc.EnsureIndex(mgo.Index{Key: []string{"key"}}) if err != nil { l.Error("Couldn't create index on sp0rkle.factoids: %v", err) } return fc }
func Collection(dbh *db.Database, l logging.Logger) *UrlCollection { uc := &UrlCollection{dbh.C(collection), l} err := uc.EnsureIndex(mgo.Index{Key: []string{"url"}, Unique: true}) if err != nil { l.Error("Couldn't create url index on sp0rkle.urls: %s", err) } for _, idx := range []string{"cachedas", "shortened"} { err := uc.EnsureIndex(mgo.Index{Key: []string{idx}}) if err != nil { l.Error("Couldn't create %s index on sp0rkle.urls: %s", idx, err) } } return uc }
func Collection(dbh *db.Database, l logging.Logger) *SeenCollection { sc := &SeenCollection{ Collection: dbh.C(COLLECTION), l: l, } err := sc.EnsureIndex(mgo.Index{ Key: []string{"key", "action"}, Unique: true, }) if err != nil { l.Error("Couldn't create index on sp0rkle.seen: %v", err) } err = sc.EnsureIndexKey("key") if err != nil { l.Error("Couldn't create index on sp0rkle.seen: %v", err) } return sc }
func Collection(dbh *db.Database, l logging.Logger) *QuoteCollection { qc := &QuoteCollection{ Collection: dbh.C(COLLECTION), seen: make(map[string][]bson.ObjectId), maxQID: 1, l: l, } err := qc.EnsureIndex(mgo.Index{Key: []string{"qid"}, Unique: true}) if err != nil { l.Error("Couldn't create index on sp0rkle.quotes: %v", err) } var res Quote if err := qc.Find(bson.M{}).Sort("-qid").One(&res); err == nil { qc.maxQID = int32(res.QID) } return qc }