I am having the below json
I want to extract the value of particular Data from Requirement array based on Id.
If "Data" = "String123" it should display the "Data" as ["WED"].
I tried this code
but I am getting all values irrespective of Id.
I am having the below json
I want to extract the value of particular Data from Requirement array based on Id.
If "Data" = "String123" it should display the "Data" as ["WED"].
I tried this code
but I am getting all values irrespective of Id.
If I get you right you have one record in "clOfferMaster" collection and you're trying to fetch data from nested collection "Eligibility". That's probably not a typical way to work with data.
What if you restructure your data as follows:
[
{
"ComponentId" : "SessionDayCheck",
"ConfigData" : [
"WED"
]
},
{
"ComponentId" : "TransDayCheck",
"ConfigData" : [
"WED",
"THU"
]
},
{
"ComponentId" : "SessionTransCheck",
"ConfigData" : ""
}
]
It that case you can do the following query
c := session.DB("offerengine2").C("clOfferMaster")
var result struct {
ConfigData []string "ConfigData"
}
err = c.Find(bson.M{"ComponentId": "SessionDayCheck"}).One(&result)
if err != nil {
log.Fatal(err)
}
fmt.Println("Result:", result)
// Result: {[WED]}