2012-02-09 31 views
1

我正在開發一個API使用Codeigniter和MongoDB(亞歷克斯Bilbie包裝),我不能讓刪除功能正常工作。Codeigniter MongoDB包裝不能使用刪除

刪除除指定的文檔以外的其他文檔!這讓我發瘋。

這是在我的模型代碼:

$where = array (

    '_id' => new MongoId ($args['id']) 

); 

$result = $this -> mongo_db -> delete ('files', $where); 

有什麼不對?我的代碼或包裝有問題嗎?

感謝您的所有意見!

回答

0

我相信你想:

$result = $this->mongo_db->where($where)->delete('files'); 

不知道你在哪裏得到你的語法 - 刪除不具有這樣的兩個參數(至少在笨封裝的版本中定義的函數我一直在使用)。

+0

包裝什麼您使用的是?在Alex的代碼示例中缺乏。 – 2012-02-10 07:22:27

+0

我也使用亞歷克斯的包裝。你必須看代碼:https://bitbucket.org/alexbilbie/codeigniter-mongo-library/src/23948e56c40c/libraries/Mongo_db.php搜索'delete',你會明白我的意思。 – 2012-02-10 13:54:12

+0

好的。那麼這不是最新的回購。使用這個:https://github.com/alexbilbie/codeigniter-mongodb-library – 2012-02-10 15:12:12

0
$where = array (

    '_id' => new MongoId ($args['id']) 

); 

$result = $this -> mongo_db -> where($where) -> delete_all('files'); 

請注意,如果您需要刪除基於嵌入式文件信息

$result = $this -> mongo_db -> where(array('field.value'=>'x') -> delete_all('files');