0

I am using riak php client and have datatype map. I want to delete entire map by key which is itemid. here is my code

        $location = new Location($itemID, $this->itemBucket);
        $map = (new \Command\Builder\FetchMap($this->riak))
        ->atLocation($location)
        ->build()
        ->execute()->getMap();

        (new \Command\Builder\UpdateMap($this->riak))
        ->removeMap($itemID)
        ->atLocation($location)
        ->withContext($map->getContext())
        ->build()
        ->execute();

but this is not working.

Kamran
  • 2,711
  • 2
  • 17
  • 24

1 Answers1

1

I think you are confusing the KV key containing a map object and a map key containing a nested map.

This location will refer to "http://riaknode:8098/buckets/$this->itemBucket/keys/$itemID"

    $location = new Location($itemID, $this->itemBucket);

This retrieves the mapt object contained by the above bucket/key

    $map = (new \Command\Builder\FetchMap($this->riak))
    ->atLocation($location)
    ->build()
    ->execute()->getMap();

This attempts to remove the element with the key $itemID from the returned map object

    (new \Command\Builder\UpdateMap($this->riak))
    ->removeMap($itemID)
    ->atLocation($location)
    ->withContext($map->getContext())
    ->build()
    ->execute();

If you want to remove the entire map stored under that bucket/key, you probably need to use a \Command\Builder\DeleteObject

Joe
  • 25,000
  • 3
  • 22
  • 44