Reputation: 6242
We are using dynamo db scan functionality to fetch all the data from dynamo like this and it works fine:
var myScanConditions = new List<ScanCondition>();
myScanConditions .Add(new ScanCondition("PartitionKey", ScanOperator.BeginsWith, "data"));
var myData= await Context.ScanAsync(myScanConditions ).GetRemainingAsync();
//some code to filter some data from above
in our dynamo db partition key is like
data#rec1
data#rec2
data#rec3
and so on
I wanted to check if we can replace Scan with Query. I tried using the below code by passing scan condition to the Query but looks like its not correct. It returns me nothing.
var myData= await Context.QueryAsync("data", myScanConditions );
So my question is there an option to provide partial text for partition key to the QueryAsync method and still return all records from dynamo. For example in my case as above if I just pass "data" (partial text) to my query async.
Is there a way to do this?
Thanks
Upvotes: 0
Views: 1595
Reputation: 8097
Unfortunately, you can't search the partition key with a Query. Queries require and only support the equal operator on the partition key.
If you truly need to search all records in your table, then you must perform a Scan as that is exactly what Scans are for although inspecting all data comes as a cost.
Some ideas to consider:
References:
Upvotes: 1
Reputation: 23783
You have to have a composite (hash key + sort key) primary key to use query.
If you had "data" as your hash (partition) key, and rec1, rec2, rec3 as the sort key, then you could query just with "data".
Upvotes: 0