Removing an array from a document?

I have a document in the following format,

"example-document": {
  _id: "example-document",
  "example-array1": [],
  "example-array2": []
}

and it’s not clear to me in the docs how to remove “example-array2” from this particular document since it’s an array and not an object. How can I just remove one particular array by name?

An array is an object. Use $unset.

db.foo.updateOne({ _id: "example-document" }, {$unset: { "example-array1": true } } )
2 Likes