Hi, I have a json data in mongodb in the format be bellow, i need help to access the data using the "nfinstanceID" which is a uuid string ID part of an api request for example example
"http://localhost:5050/nnrf-nfm/v1/nf-instances/3fa85f64-5717-4562-b3fc-2c963f66afaa" The api route is of the form ""......./nnrf-nfm/v1/nf-instances/{nfinstanceID}" instead of using "bson.ObjectId". My struct is in the format type NfInstance struct { ID bson.ObjectId `bson:"_id" json:"id"` ValidityPeriod int `json:"validityPeriod" bson:"validityPeriod"` NfInstanceID string `json:"nfinstanceID" bson:"nfinstanceID"` SNssais []Snssai `json:"sNssais" bson:"sNssais"` NfServices []Service `json:"nfServices" bson:"nfServices"` ....... } type Service struct { ServiceInstanceID string `json:"serviceInstanceId" bson:"serviceInstanceId"` Versions []Version `json:"versions" bson:"versions"` } type Version struct { APIVersionInURI string `json:"apiVersionInUri" bson:"apiVersionInUri"` ....... } type Snssai struct { Sst int32 `json:"sst"` ..... } // Fuctions are // Find a instance by its id func (m *NfInstanceDataAccess) FindById(id string) (NfInstance, error) { var nfinstance NfInstance err := db.C(COLLECTION).FindId(bson.ObjectIdHex(id)).One(&nfinstance) return nfinstance, err } // Handler function func NfInstancebyIdGet(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) id := vars["nfinstanceID"] nfinstance, err := da.FindById(id) if err != nil { respondWithError(w, http.StatusBadRequest, "Invalid nfinstance ID") return } respondWithJson(w, http.StatusOK, nfinstance) } Using this functions work but i would like to access the data not using bson.ObjectId but rather "nfinstanceID" part. Completely new to golang. Thanks in advance!! Abraham { "id": "5c6c238dfdde24520f7b1b69", "validityPeriod": 1, "nfinstanceID": "3fa85f64-5717-4562-b3fc-2c963f66afaa", "heartBeatTimer": 0, "nfType": "string", "nfStatus": [ "REGISTERED" ], "sNssais": [ { "sst": 0, "sd": "string" } ], "nsiList": [ "string" ], "nfServices": [ { "serviceInstanceId": "string", "versions": [ { "apiVersionInUri": "http://{apiRoot}/v1/xxx", "apiFullVersion": "string", "expiry": "2019-02-03T14:08:56.65+02:00" } ] } ] } -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.