2011-10-22 236 views
1

刪除數據I具有從蒙戈獲得的下一數組:從蒙戈文件用PHP

array(10) { 
    ["_id"]=> 
    object(MongoId)#25 (1) { 
    ["$id"]=> 
    string(24) "4ea062b9271e012227000000" 
    } 
    ["email"]=> 
    string(18) "[email protected]" 
    ["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" 
} 

否則我已經加入不良信息到該文件的測試,最後2個鍵陣列的:0和1。我的問題是我如何刪除Mongo和使用PHP的信息或其他標籤?

預先感謝您!

回答

0

在這種情況下,你需要確切的命令是:

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 
    ]] 
);