+func FixGranularity(props bson.D) bson.D {
|
+ propsMap := props.Map()
|
+
|
+ // If we got granularity, then the server will actually forbid
|
+ // bucketRoundingSeconds. So we should be done.
|
+ if _, hasGranularity := propsMap["granularity"]; hasGranularity {
|
+ return props
|
+ }
|
+
|
+ // Check for bucketMaxSpanSeconds (“mss”).
|
+ if mss, hasMSS := propsMap["bucketMaxSpanSeconds"]; hasMSS {
|
+
|
+ // If we got mss *and* rounding-seconds, then we should be done.
|
+ if _, hasRounding := propsMap["bucketRoundingSeconds"]; hasRounding {
|
+ return props
|
+ }
|
+
|
+ // If mss matches a “granularity” preset, then just use that.
|
+ granularity, granOk := maxSpanSecondsToGranularity[cast.ToInt(mss)]
|
+ if granOk {
|
+ mbson.DReplace(props, "bucketMaxSpanSeconds", "granularity", granularity)
|
+ return props
|
+ }
|
+
|
+ // Finally: if we have a custom max-span-seconds and no granularity,
|
+ // then just assign the mss value as rounding-seconds.
|
+ props = append(props, bson.D{{"bucketRoundingSeconds", mss}}...)
|
+ }
|
+
|
+ return props
|
+}
|