Hi,

I have the JSON below in mongodb collection

{
  "Id":"3fa85f64-5717-4562-b3fc-2c963f66afa6",
  "allowedNssaiList": [
    {
      "allowedSnssaiList": [
        {
          "allowedSnssai": {
            "sst": 1,
            "sd": "2"
          },
          "IMSI": "244340000000001",
          "tac": "3022"
        }
      ],
      "accessType": "3GPP_ACCESS"
    }
  ]}
 

I would like to append to the sub array allowedSnssaiList with the object


        {
          "allowedSnssai": {
            "sst": 1,
            "sd": "2"
          },
          "IMSI": "244340000000001",
          "tac": "3022"
        }

I have tried with the following


selector := bson.M{"_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6"}PushToArray := 
bson.M{"$addToSet": bson.M{"allowedSnssaiList": bson.M{"allowedSnssai": 
bson.M{"sst": 3,"sd": "4"}, "IMSI": "244510000000004","tac": "3022"}}}

err := db.C(COLLECTION).Update(selector, PushToArray)

but when i push, it does not append well, i get 

{
  "_id":"3fa85f64-5717-4562-b3fc-2c963f66afa6",
  "allowedNssaiList": [
    {
      "allowedSnssaiList": [
        {
          "allowedSnssai": {
            "sst": 1,
            "sd": "2"
          },
          "IMSI": "244340000000001",
          "tac": "3022"
        }
      ],
      "accessType": "3GPP_ACCESS"
    }
  ],
  "allowedSnssaiList" : [
        {
            "allowedSnssai" : {
                "sst" : 1,
                "sd" : "5"
            },
            "IMSI" : "244340000000005",
            "tac" : "3022"
        }
    ]}


but i want the result or append as



{
  "_id":"3fa85f64-5717-4562-b3fc-2c963f66afa6",
  "allowedNssaiList": [
    {
      "allowedSnssaiList": [
        {
          "allowedSnssai": {
            "sst": 1,
            "sd": "2"
          },
          "IMSI": "244340000000001",
          "tac": "3022"
        },
        {
                "allowedSnssai" : {
                    "sst" : 1,
                    "sd" : "5"
                },
                "IMSI" : "244340000000005",
                "tac" : "3022"
            }
      ],
      "accessType": "3GPP_ACCESS"
    }
  ]}

changing to

PushToArray := bson.M{"$addToSet": 
bson.M{"allowedNssaiList[0].allowedSnssaiList[0]": bson.M{"allowedSnssai": 
bson.M{"sst": 3,"sd": "4"}, "IMSI": "244510000000004","tac": "3022"}}}

still did not work, any help?

Abraham


-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/3f8eb588-59a4-4501-bce0-3bca0bfb3795%40googlegroups.com.

Reply via email to