Example #1
0
// Retrieves all tags in the provided list that match the provided where clause.
func (m *mongoStore) GetTags(tags []string, where bson.M) (common.SmapMessageList, error) {
	var (
		staged      *mgo.Query
		selectTags  bson.M
		whereClause bson.M
		x           []bson.M
	)
	if len(where) != 0 {
		whereClause = make(bson.M)
		for wk, wv := range where {
			whereClause[common.FixMongoKey(wk)] = wv
		}
	}
	staged = m.metadata.Find(whereClause)
	if len(tags) == 0 { // select all
		selectTags = bson.M{"_id": 0, "_api": 0}
	} else {
		selectTags = bson.M{"_id": 0}
		for _, tag := range tags {
			selectTags[common.FixMongoKey(tag)] = 1
		}
	}
	err := staged.Select(selectTags).All(&x)
	// trim down empty rows
	filtered := x[:0]
	for _, doc := range x {
		if len(doc) != 0 {
			filtered = append(filtered, doc)
		}
	}
	return common.SmapMessageListFromBson(filtered), err
}
Example #2
0
func (m *mongoStore) GetDistinct(tag string, where bson.M) (common.DistinctResult, error) {
	var (
		result      common.DistinctResult
		whereClause bson.M
		fixedTag    = common.FixMongoKey(tag)
	)
	if len(where) != 0 {
		whereClause = make(bson.M)
		for wk, wv := range where {
			whereClause[common.FixMongoKey(wk)] = wv
		}
	}
	err := m.metadata.Find(where).Distinct(fixedTag, &result)
	return result, err
}
Example #3
0
func (m *mongoStore) GetUUIDs(where bson.M) ([]common.UUID, error) {
	var results []common.UUID
	var x []bson.M
	var whereClause bson.M
	if len(where) != 0 {
		whereClause = make(bson.M)
		for wk, wv := range where {
			whereClause[common.FixMongoKey(wk)] = wv
		}
	}
	selectClause := bson.M{"_id": 0, "uuid": 1}
	err := m.metadata.Find(where).Select(selectClause).All(&x)
	results = make([]common.UUID, len(x))
	for i, doc := range x {
		results[i] = common.UUID(doc["uuid"].(string))
	}
	return results, err
}