I'm using MongoDB to store my data. I got a collection whichs documents have this look:
{
"_id": UUID("61d2a9c4-0d8a-4106-ab50-8d4ada96bfdf"),
"some": "field",
"data": {
"1d19bca7-7edb-4085-a2c3-fa92c6faf3bd": {
"a": "nested object"
},
"7f812369-c4ff-4e90-9f2c-27904bb03e8d": {
"a": "nother nested object"
}
}
}
I would now like to remove data.7f812369-c4ff-4e90-9f2c-27904bb03e8d
. I tried it with $unset
but you can just set the field to null
but not remove it. Another approach I did was using $pull
but I thinks it's only assumed to be used for arrays. So how could I remove the data.7f812369-c4ff-4e90-9f2c-27904bb03e8d
field?
Any help appreciated
EDIT:
db.getCollection('mycollection').update({
"_id": UUID("61d2a9c4-0d8a-4106-ab50-8d4ada96bfdf")
}, {
$unset: {
"data.1d19bca7-7edb-4085-a2c3-fa92c6faf3bd": null
}
});
actually works. Can't remember what I did wrong the other when. Thanks alot to everybody helping.