我最近在研究yii2。我在后端数据库中使用 mongodb。我对在文档中找到的更新查询感到困惑
public function actionUpdate($id)
{
$query = new Query;
$row = $query->from('item')
where(['_id' => $id]) // implicit typecast to [['MongoId]]
->one();
...
}
我正在编写特定于 php 的 mongodb 查询,如下所示...
$update = array('$set' => array("status" => 'read', "agencyStatus" => 'unread'));
$where = array("_id" => new MongoId($id));
$mongoDb->update($where, $update);
Yii2 特定 mongodb 中的语法如何???
您可以使用 gii(video) 生成 Mongo 模型,并在控制器中执行以下操作:
$item = Item::find()->where(["_id" => new MongoId($id)]);
$item->status = 'read';
$item->agencyStatus= 'unread';
$item->save();