Retrieves one or more items and its attributes by performing a full scan of a table.
Provide a ScanFilter to get more specific results.
Declaration Syntax
C# |
ScanResponse Scan( ScanRequest scanRequest )
Parameters
- scanRequest (ScanRequest)
- Container for the necessary parameters to execute the Scan service method on AmazonDynamoDB.
Return Value
The response from the Scan service method, as returned by AmazonDynamoDB.
Examples
The following example shows how to scan items in a table.
Note: the Scan operation goes through every item in the table
to check if the item matches all the scan conditions. This makes
the Scan operation particularly slow and expensive (in terms of provisioned throughput).
We will now retrieve all items where the Pages attribute is greater
than the numerical value "200" and where the Title attribute contains
the string "Adventures".
CopyScan sample
// Create a client AmazonDynamoDBClient client = new AmazonDynamoDBClient(); // Define scan conditions Dictionary<string, Condition> conditions = new Dictionary<string,Condition>(); // Title attribute should contain the string "Adventures" Condition titleCondition = new Condition(); titleCondition.WithComparisonOperator("CONTAINS"); titleCondition.WithAttributeValueList(new AttributeValue { S = "Adventures"}); conditions["Title"] = titleCondition; // Pages attributes must be greater-than the numeric value "200" Condition pagesCondition = new Condition(); pagesCondition.WithComparisonOperator("GT"); pagesCondition.WithAttributeValueList(new AttributeValue { N = "200"}); conditions["Pages"] = pagesCondition; // Define marker variable Key startKey = null; do { // Create Scan request ScanRequest request = new ScanRequest { TableName = "SampleTable", ExclusiveStartKey = startKey, ScanFilter = conditions }; // Issue request ScanResult result = client.Scan(request).ScanResult; // View all returned items List<Dictionary<string, AttributeValue>> items = result.Items; foreach (Dictionary<string, AttributeValue> item in items) { Console.WriteLine("Item:"); foreach (var keyValuePair in item) { Console.WriteLine("{0} : S={1}, N={2}, SS=[{3}], NS=[{4}]", keyValuePair.Key, keyValuePair.Value.S, keyValuePair.Value.N, string.Join(", ", keyValuePair.Value.SS.ToArray()), string.Join(", ", keyValuePair.Value.SS.ToArray())); } } // Set marker variable startKey = result.LastEvaluatedKey; } while (startKey != null);
Exceptions