mongodb $pull not working php -
i have object in db.
array( [_id] => mongoid object ( [$id] => 4fcdb3b8749d786c03000002 ) [email] => foo@bar.com [folder] => array ( [root] => array ( [feeds] => array ( [0] => array ( [feedid] => mongoid object ( [$id] => 4fcdaa9e749d786c03000001 ) [title] => title.com ) ) [title] => root ) ) [status] => 1 [username] => foouser) i want pull item [0] [feeds]. use code not working:
$userscollection->update(array("username" => "foouser"), array('$pull'=> array('folder'=>array('root'=>array('feeds'=>array('feedid'=>$id)))))); when use $unset instead of $pull, full of [folder] gone.
you need specify full value of array element. have use 'folder.root.feeds' that's field want pull from. don't want pull array element inside folder being affected.
on shell, run:
db.so.update( { 'username' : 'foouser' }, { $pull: { 'folder.root.feeds' : { "feedid" : objectid("4fcdaa9e749d786c03000001"), "title" : "title.com" } } } ); and in php, translate to:
$c->update( array( 'username' => 'foouser' ), array( '$pull' => array( 'folder.root.feeds' => array( 'feedid' => new mongoid('4fcdaa9e749d786c03000001'), 'title' => 'title.com', ) ) ) );
Comments
Post a Comment