Delete a field of document of mongodb using active record while updating a document

I dont know if its an issue. But i cant find a way to unset a field of a document of mongodb in yii2 using active record

For Example my document in mongodb:

{

"_id" : ObjectId("57c00b6a9eb895682e0e3235"),

"order_id" : 1,

"customer_id" : "5799f2549eb895a412000153",

"placed" : "2016-08-30 14:09:59"

}

and i want to unset the placed field so it can become

{

"_id" : ObjectId("57c00b6a9eb895682e0e3235"),

"order_id" : 1,

"customer_id" : "5799f2549eb895a412000153"

}

Thanks,

I don’t think you cat use activeRecord for that. You can use Yii2 [color=#000000]MongoDB[/color] command or yii2 [color=#000000]MongoDB[/color] collection. There are a few ways in MongoDB you can do this but this is how using the MongoDB $unset..

Using the collection method


Yii::$app->mongodb->getCollection('orders')->update(['_id' =>new \MongoId($id)],['$unset' => ['placed'=>'']]);