@shibbir Does it work for you?
DB::connection('mongodb')->collection( $collection )->where( 'id', $id )->update( [ '$unset' => [ 'aff_link' => 1, 'availability' => 1 ] ] );
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
In the mongodb database I have multiple documetns and each document contain this type of data:
{
"_id": {
"$oid": "636b7f0f889929ce62194c28"
},
"id": "SK7732.1825+1",
"aff_link": "https://go.linkwi.se/z/11593-0/CD24352/?lnkurl=https%3A%2F%2Fwww.celestino.gr%2Fel-GR%2Fpanteloni-me-pietes-lefko%2Fprd%2FSK7732.1825%2F7%3Faffiliate%3Dlinkwise%26utm_source%3Dlinkwise%26utm_medium%3Dlw%26utm_campaign%3Dlw",
"availability": "Y",
"brand": "Celestino",
"color": [],
"date_add": 1667989263,
"date_upd": 1674697681,
"description": "Παντελόνι με πιέτες, κλείσιμο με φερμουάρ και κουμπί, θηλιές στη μέση, με τσέπες, λευκο",
"image_link": "https://2ccdn.celestino.gr/small/[email protected]",
"link": "https://www.celestino.gr/el-GR/panteloni-me-pietes-lefko/prd/SK7732.1825/7?affiliate=linkwise&utm_source=linkwise&utm_medium=lw&utm_campaign=lw",
"part_number": "SK7732.1825.1",
"price": "13,99",
"product_type": "Παντελόνια/Παντελόνια",
"sizes_in_stock_feed": "S",
"title": "Παντελόνι με πιέτες SK7732.1825+1",
"update_history": [
{
"id_feed": 169,
"feed_name": "from linkwise",
"date_upd": 1674689686,
"field_history": []
},
{
"id_feed": 170,
"feed_name": "scrape info",
"date_upd": 1674697681,
"field_history": [
{
"field_name": "all_sizes",
"removable": 1,
"updatable": 1,
"date_upd": 1674697681
},
{
"field_name": "sizes_in_stock",
"removable": 1,
"updatable": 1,
"date_upd": 1674697681
},
{
"field_name": "breadcrumbs",
"removable": 1,
"updatable": 1,
"date_upd": 1674697681
},
{
"field_name": "breadcrumbs_url",
"removable": 1,
"updatable": 1,
"date_upd": 1674697681
},
{
"field_name": "color",
"removable": 1,
"updatable": 1,
"date_upd": 1674697681
}
]
}
],
}
From this data I can get the data based on id .for example:
$get_product = DB::connection('mongodb')->collection( $collection )->where( 'id', $id )->first();
Now, Is there anyway I can delete single or multiple keys from the document based on id?
For example, I want to delete the aff_link and availability key.
@shibbir Does it work for you?
DB::connection('mongodb')->collection( $collection )->where( 'id', $id )->update( [ '$unset' => [ 'aff_link' => 1, 'availability' => 1 ] ] );
Please or to participate in this conversation.