baopham/laravel-dynamodb

Unable to get records as per sort_key

connect-javed001 opened this issue · 16 comments

Trying to get records in descending order, but it's always returns same result, I have sort_key (as current timestamp), can u please help me ?

Also provide solution when we want to search records based on date filter using sort key

What code are you using? Have you delcared the index in your model?

No, Defined primaryKey & compositeKey only

Can you show us your model?

namespace App\Models;

use BaoPham\DynamoDb\DynamoDbModel;

class Activity extends DynamoDbModel
{
    protected $table;
    protected $primaryKey;
    protected $compositeKey;

    public function __construct()
    {
        $this->primaryKey = config('dynamodb.connections.aws.hash_key');
        $this->compositeKey = [
            config('dynamodb.connections.aws.hash_key'),
            config('dynamodb.connections.aws.sort_key')
        ];
        $this->table = "Activity";
    }
}

Could you try using the index?

/**
 * Indexes.
 * [
 *     '<simple_index_name>' => [
 *          'hash' => '<index_key>'
 *     ],
 *     '<composite_index_name>' => [
 *          'hash' => '<index_hash_key>',
 *          'range' => '<index_range_key>'
 *     ],
 * ]
 *
 * @var array
 */
protected $dynamoDbIndexKeys = [
    'count_index' => [
        'hash' => 'count'
    ],
];

where we need to define above index ?

In the model?

Did it work?

No. Still getting same issue

What does your model look like now?

namespace App\Models;

use BaoPham\DynamoDb\DynamoDbModel;

class ActivityTracking extends DynamoDbModel
{
    protected $table;
    protected $primaryKey;
    protected $compositeKey;

    /**
     * Indexes.
     * [
     *     '<simple_index_name>' => [
     *          'hash' => '<index_key>'
     *     ],
     *     '<composite_index_name>' => [
     *          'hash' => '<index_hash_key>',
     *          'range' => '<index_range_key>'
     *     ],
     * ]
     *
     * @var array
     */
    protected $dynamoDbIndexKeys = [
        'count_index' => [
            'hash' => 'count'
        ],
    ];

    public function __construct()
    {
        $this->primaryKey = config('aws.hash_key');
        $this->compositeKey = [
            config('aws.hash_key'),
            config('aws.sort_key')
        ];
        $this->table = "ActivityTracking";
    }
}

Are you using withIndex('count_index') ?

Yes, But at server end, Index not defined

Is it compulsory to create index for sorting ?

You’ll need to create the index before you can use it.