0

I have following collection which looks like below:-

{
    "_id" : ObjectId("5aba0f8fd19bc9314089a9ba"),
    "repoha" : [ ],
    "name" : "myrep2",
    "repo_number" : 4,
    "store_front_port" : null,
    "old_repo_paths" : [
        {
            "path" : "/opt/immune/storage/",
            "retention" : 2
        },
        {
            "path" : "/secondarytier/",
            "retention" : 10
        },
        {
            "path" : "/teritarydir/dir1/",
            "retention" : 3
        }
    ],
    "repopath" : [
        {
            "path" : "/opt/immune/storage/",
            "retention" : 2
        },
        {
            "path" : "/teritarydir/dir1/",
            "retention" : 3
        }
    ],
    "tid" : "",
    "used_size" : "0.00781 MB",
}

how to remove the key named "old_repo_paths" and with any value in it so that collection will look like

{
    "_id" : ObjectId("5aba0f8fd19bc9314089a9ba"),
    "repoha" : [ ],
    "name" : "myrep2",
    "repopath" : [
        {
            "path" : "/opt/immune/storage/",
            "retention" : 2
        },
        {
            "path" : "/teritarydir/dir1/",
            "retention" : 3
        }
    ],
    "tid" : "",
    "used_size" : "0.00781 MB",
}

I have tried unset method along but getting errors db.repo.update({_id:ObjectId("5aba0f8fd19bc9314089a9ba")},{$unset: {old_repo_paths}});

sherpaurgen
  • 3,028
  • 6
  • 32
  • 45
  • 1
    have a look: https://stackoverflow.com/questions/6851933/how-to-remove-a-field-completely-from-a-mongodb-document/6852039 – dkb Apr 04 '18 at 12:12
  • Thanks @dkb ill will remove this question if i find its a duplicate question – sherpaurgen Apr 04 '18 at 12:14

0 Answers0