使用PHP从mongo文档中删除数据

使用PHP从mongo文档中删除数据,php,mongodb,Php,Mongodb,我从Mongo获得了下一个数组: array(10) { ["_id"]=> object(MongoId)#25 (1) { ["$id"]=> string(24) "4ea062b9271e012227000000" } ["email"]=> string(18) "your@email.tld" ["group"]=> int(1) ["last_login"]=> int(1319299712) [

我从Mongo获得了下一个数组:

array(10) {
  ["_id"]=>
  object(MongoId)#25 (1) {
    ["$id"]=>
    string(24) "4ea062b9271e012227000000"
  }
  ["email"]=>
  string(18) "your@email.tld"
  ["group"]=>
  int(1)
  ["last_login"]=>
  int(1319299712)
  ["login_hash"]=>
  string(40) "a67b25998576d454c7a422908592ed338561a527"
  ["password"]=>
  string(44) "EK341WsJRo1vUB9vGYWfogfzstZsIg77/oRqlpeQH+I="
  ["profile_fields"]=>
  string(6) "a:0:{}"
  ["username"]=>
  string(7) "loremipsum"
  [0]=>
  string(10) "login_hash"
  [1]=>
  string(40) "9de77184cb57625f834879b3cbcdf0b860d842c1"
}
在进行测试时,我向该文档中添加了错误信息,数组的最后两个键:0和1。我的问题是如何使用Mongo和PHP删除该信息或其他标签


提前谢谢你

不知道如何在php中处理它,但可以使用修饰符删除单个字段:$unset。在这种情况下,您需要的确切命令是:

db.collection.update(
    {"_id": ObjectID("4ea062b9271e012227000000")},
    {"$unset": [0: true, 1: true]}
);
在php中,这类似于:

$mongoClient = new MongoClient();
$db = $mongoClient->selectDB('your_DB_name');
$collection = new MongoCollection($db, 'your_collection_name');
$collection->update(
    ['_id' => new MongoId("4ea062b9271e012227000000")],
    ['$unset' => [
        0 => true,
        1 => true
    ]]
);