我无法使用PHP
删除MongoDB中的文档以下是我的代码:
<?php
$end = new MongoDate(strtotime("2011-01-30 00:00:00"));
// connect
$m = new MongoClient();
// select a database
$db = $m->selectdb("testdb");
$collections = $db->listCollections();
foreach ($collections as $collection) {
echo $collection."<br />";
$cursor = $collection->find(array('created_at'=>array('$lte' => $end)));
foreach ($cursor as $doc) {
//db.orders.deleteMany( { "client" : "Crude Traders Inc." } );
$did = $doc['_id'];
echo $did;
echo '<br>';
echo $doc['name'];
echo $collection;
$ret = $collection->remove(array('_id' => new MongoId($did)), true);
}}
?>
我可以获取列表,但无法删除单行。我没有找到合适的网络,或者我正在做一些愚蠢的错误。