1

I am using DynamoDB and zend framework.

I am able to fetch row from normal table using this.

$response['Items'] = $this->dbClient->query(
     array(
        "TableName" => "user",
        "KeyConditions" =>  array( 
                               "userId" => array(
                                             "ComparisonOperator" => ComparisonOperator::EQ,
                                             "AttributeValueList" => array(
                                                                       array(Type::NUMBER => 2))
                                                                     )
                                              )
                               )
           );

But How I can fetch information based on Global secondary indexes. I have two fields in this table Id and email.

I want to search based on email and getting Id from Global secondary index table. And I want to use this id to get user's all other information from main user table. I want to do this in local DynamoDB.

How I can fetch id based on email from Global secondary index table in zend framework?

keen
  • 3,001
  • 4
  • 34
  • 59
  • is "email" primary key? Then it should work to get the id by fetching a row by email (its primary key). and the use that id. I don't understand why your main user table doesn't have setup the "email" as secondary index and that should solve the problem right away. Mind that secondary indexes could be created when the table is created. As well you need to specify what columns are available to be retrieved through the secondary index. – tavi Jan 08 '14 at 14:02
  • this is database design for DynamoDB. Yes I am creating secondary index table after creating table. – keen Jan 09 '14 at 09:44

1 Answers1

1

You just have to add index name while query, but in your global index email should be hash here all the attribute will be projected.

   $response = $this->dbClient->query(
       array(
            "TableName" => "user",
            "IndexName" => "index name",
            "KeyConditions" => array(
                 "email" => array(
                      "ComparisonOperator" => ComparisonOperator::EQ,
                      "AttributeValueList" => array(
                          array(Type::STRING => "email@abc.com"))))));

then you can fetch userId

ApproachingDarknessFish
  • 14,133
  • 7
  • 40
  • 79
Harshal Bulsara
  • 7,898
  • 4
  • 43
  • 61