type Record struct { RecordID string `json:"recordID" bson:"_id"` CreatedOn time.Time `json:"createdOn" bson:"created_on"` LastUpdatedOn time.Time `json:"lastUpdatedOn" bson:"last_updated_on"` Kind Kind `json:"kind" bson:"kind"` Data RecordData `json:"data" bson:"data"`}
// RecordData is a map of typed-backed key-values for a Recordtype RecordData map[string]TypedValue
// SetString adds a new key with a string valuefunc (d RecordData) SetString(name, value string) { d[name] = TypedValue{Type: ValueTypeString, Value: value}}
// SetNumber adds a new key with a float64 valuefunc (d RecordData) SetNumber(name string, value float64) { d[name] = TypedValue{Type: ValueTypeNumber, Value: value}}
// SetDate adds a new key with a time.Time valuefunc (d RecordData) SetDate(name string, value time.Time) { d[name] = TypedValue{Type: ValueTypeDate, Value: value}}
// TypedValue bundles a interface{} with a ValueTypetype TypedValue struct { Type ValueType `json:"type" bson:"type"` Value interface{} `json:"value" bson:"value"`}
// ValueType specifies the type of a TypedValuetype ValueType string
const ( // ValueTypeString specifies the Value is of type String ValueTypeString ValueType = "string" // ValueTypeNumber specifies the Value is of type float64 ValueTypeNumber ValueType = "number" // ValueTypeDate specifies the Value is of type time.Time ValueTypeDate ValueType = "date")
rd := ps.RecordData{}
rd.SetDate("status_date", time.Now())
rd.SetString("status_severity", "asdf")
rd.SetNumber("status_codes", 1123.0)
"status_date" : {
"type" : "date",
"value" : "2016-03-14T15:13:55.5802835-07:00" // I would expect this to be an ISODate()
},
"status_severity" : {
"type" : "string",
"value" : "asdf"
},
"status_codes" : {
"type" : "number",
"value" : 1123.0
}
func (s *store) Upsert(id string, kind spec.Kind, data spec.RecordData) (response spec.Record, err error) { s.mgoSearchHandler(func(db *mgo.Database) { now := time.Now()
set := bson.M{ "last_updated_on": now, }
for key, val := range data { set["data."+key] = val }
change := mgo.Change{ ReturnNew: true, Upsert: true, Update: bson.M{ "$set": set, "$setOnInsert": bson.M{ "_id": id, "created_on": now, "kind": kind, }, }, }
_, err = db.C(cSearchRecords).FindId(id).Apply(change, &response) })
return response, err}
--
You received this message because you are subscribed to the Google Groups "mgo-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mgo-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "mgo-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mgo-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.