简体   繁体   中英

How limit scan results in DynamoDB .NET

i have a question. I want to limit the result of scan over dynamodb. I read in documentation that "Limit" parameter on ScanRequest do this works, but this code it seems not working.

I have 14 records, and this scan returns exactly 14 records, but should return 10. What i am doing wrong?

public IList<Contact> GetContacs(string firstContactToScan)
        {
            using (var context = new DynamoDBContext(new AmazonDynamoDBClient()))
            {
                var data = context.FromScan<Contact>(new ScanOperationConfig {Limit = 10}).ToList();
                return data;
            }
        }

Thanks

You can try following code:

AmazonDynamoDBClient client = new AmazonDynamoDBClient();

var request = new ScanRequest
{
    TableName = "yourTableName",
    Limit = 10
};

var response = client.Scan(request);
var result = response.ScanResult;

foreach (Dictionary<string, AttributeValue> item in response.ScanResult.Items)
{
  PrintItem(item);
}

There are other options also which you can specify in the request following is the Reference Link .

Hope that helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM