How to i query mongodb using golang bson to retrieve the ipv4Address field in the document. Am using the nfType field as a query parameter.
currently, mongo distinct out only array of the form
var ip []string
query := bson.M{"nfType": "SMF"}
err := db.C(COLLECTION).Find(query).Distinct("ipv4Addresses", &ip)
result
["198.51.100.1"]
however, I want the field as
{ "ipv4Addresses": [ "198.51.100.1"] }
or
[{ "ipv4Addresses": [ "198.51.100.1"] }]
The JSON document in the collection is of the form
{
"nfType": [
"SMF"
],
"nfStatus": [
"REG"
],
"sNssais": [
{
"sst": 1,
"sd": "sd1"
}
],
"nsiList": [
"NSI-ID1"
],
"ipv4Addresses": [
"198.51.100.1"
]
}