Yii2 MongoDB 从文档中删除单行数据

huangapple go评论71阅读模式
英文:

Yii2 MongoDB delete single row from document

问题

尝试删除但无法成功的两种方式如下:

尝试一:

$query = new Query();
$query->delete()->from('table_name')->where(['disease_id' => 'A0PO919Q-12', 'status' => 1]);

尝试二:

$collection = Yii::$app->mongodb->getCollection('table_name');
$collection->delete(['disease_id' => 'A0PO919Q-12']);

有人可以尝试在Yii2框架中从MongoDB中删除数据吗?

英文:

I try this two way to delete but unable to do so:--

Try one:-

$query = new Query();
$query->delete()->from('table_name')->where(['disease_id' => 'A0PO919Q-12', 'status' => 1]);

Try Two:-

$collection = Yii::$app->mongodb->getCollection('table_name');
$collection->delete(['disease_id' => 'A0PO919Q-12']);

Can anyone try to delete data from mongo DB in Yii2 Framewrok

答案1

得分: 0

我找到了解决方案

$collection = Yii::$app->mongodb->getCollection('table_name');
$collection->remove(['disease_id' => 'A0PO919Q-12']);
英文:

I find the solution

$collection = Yii::$app->mongodb->getCollection('table_name');
$collection->remove(['disease_id' => 'A0PO919Q-12']);

huangapple
  • 本文由 发表于 2020年1月6日 15:43:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/59608356.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定