コード例 #1
0
func (m *MongoAggregatePump) ensureIndexes(c *mgo.Collection) error {
	var err error
	ttlIndex := mgo.Index{
		Key:         []string{"expireAt"},
		ExpireAfter: 0,
		Background:  true,
	}

	err = mgohacks.EnsureTTLIndex(c, ttlIndex)
	if err != nil {
		return err
	}

	apiIndex := mgo.Index{
		Key:        []string{"timestamp"},
		Background: true,
	}

	err = c.EnsureIndex(apiIndex)
	if err != nil {
		return err
	}

	orgIndex := mgo.Index{
		Key:        []string{"orgid"},
		Background: true,
	}

	err = c.EnsureIndex(orgIndex)
	if err != nil {
		return err
	}

	return nil
}
コード例 #2
0
func (m *MongoSelectivePump) ensureIndexes(c *mgo.Collection) error {
	var err error
	ttlIndex := mgo.Index{
		Key:         []string{"expireAt"},
		ExpireAfter: 0,
		Background:  true,
	}

	err = mgohacks.EnsureTTLIndex(c, ttlIndex)
	if err != nil {
		return err
	}

	apiIndex := mgo.Index{
		Key:        []string{"apiid"},
		Background: true,
	}

	err = c.EnsureIndex(apiIndex)
	if err != nil {
		return err
	}

	orgIndex := mgo.Index{
		Key:        []string{"orgid"},
		Background: true,
	}

	err = c.EnsureIndex(orgIndex)
	if err != nil {
		return err
	}

	idOrgIndex := mgo.Index{
		Key:        []string{"_id", "orgid"},
		Background: true,
	}

	err = c.EnsureIndex(idOrgIndex)
	if err != nil {
		return err
	}

	idOrgApiIndex := mgo.Index{
		Key:        []string{"_id", "orgid", "apiid"},
		Background: true,
	}

	err = c.EnsureIndex(idOrgApiIndex)
	if err != nil {
		return err
	}

	idOrgErrIndex := mgo.Index{
		Key:        []string{"_id", "orgid", "responsecode"},
		Background: true,
	}

	err = c.EnsureIndex(idOrgErrIndex)
	if err != nil {
		return err
	}

	return nil
}