Esempio n. 1
0
func buildSearchClauses(criteria MetadataFilter) bson.D {
	all := bson.D{}

	if criteria.Stream != "" {
		all = append(all, bson.DocElem{"stream", criteria.Stream})
	}

	if criteria.Region != "" {
		all = append(all, bson.DocElem{"region", criteria.Region})
	}

	if len(criteria.Series) != 0 {
		all = append(all, bson.DocElem{"series", bson.D{{"$in", criteria.Series}}})
	}

	if len(criteria.Arches) != 0 {
		all = append(all, bson.DocElem{"arch", bson.D{{"$in", criteria.Arches}}})
	}

	if criteria.VirtType != "" {
		all = append(all, bson.DocElem{"virt_type", criteria.VirtType})
	}

	if criteria.RootStorageType != "" {
		all = append(all, bson.DocElem{"root_storage_type", criteria.RootStorageType})
	}

	if len(all.Map()) == 0 {
		return nil
	}
	return all
}
Esempio n. 2
0
//func getMo
func (keymap RequestMongoKeyMap) ParseRequestToMongoQuery() bson.M {
	var bsonarr bson.D
	for key, value := range keymap {
		//		fmt.Println("key")
		//		fmt.Println(value)
		if value != nil && value != "" && value != 0 {
			//			fmt.Println(key)
			//			fmt.Println(value)
			bsonarr = append(bsonarr, bson.DocElem{key, value})
		}
	}
	//	fmt.Println(bsonarr.Map())
	return bsonarr.Map()
}
Esempio n. 3
0
func (keymap RequestMongoKeyMap) SetTimeSection(key string, begintime int64, endtime int64) {
	if begintime != 0 || endtime != 0 {
		var bsonarr bson.D
		if begintime != 0 {
			bsonarr = append(bsonarr, bson.DocElem{"$gt", begintime})
		}
		if endtime != 0 {
			bsonarr = append(bsonarr, bson.DocElem{"$lt", endtime})
		}
		keymap[key] = bsonarr.Map()
		//		return bsonarr.Map()

		//		(*keymap)[key] = bsonarr.Map()
	}
	//	fmt.Println("time nil")
	//	return nil
}
Esempio n. 4
0
//todo test
func GetTimeSection(begintime int64, endtime int64) bson.M {
	//	fmt.Println(begintime)
	//	fmt.Println(endtime)
	if begintime != 0 || endtime != 0 {
		var bsonarr bson.D
		if begintime != 0 {
			//			fmt.Println("add starttime")
			bsonarr = append(bsonarr, bson.DocElem{"$gt", begintime})
		}
		if endtime != 0 {
			bsonarr = append(bsonarr, bson.DocElem{"$lt", endtime})
		}
		//		keymap[key]=bson.M{"$gt": begintime,""}
		return bsonarr.Map()
		//		(*keymap)[key] = bsonarr.Map()
	}
	//	fmt.Println("time nil")
	return nil
}
Esempio n. 5
0
func (s *S) TestDMap(c *C) {
	d := bson.D{{"a", 1}, {"b", 2}}
	c.Assert(d.Map(), DeepEquals, bson.M{"a": 1, "b": 2})
}