Dynamoose provides the ability to scan a model by using the
Model.scan function. This function acts as a builder to construct your scan with the appropriate settings before executing it (
Scan operations run on every document in your table or index. This means that all filtering is done after the documents are read, and therefore is not the most performant method. Due to that, if possible, it is highly encouraged to use
Model.query as opposed to
This is the basic entry point to construct a scan request. The filter property is optional and can either be an object or a string representing the key you which to first filter on. In the event you don't pass in any parameters and don't call any other methods on the scan object it will scan with no filters or options.
If you pass an object into
Model.scan the object for each key should contain the comparison type. For example, in the last example above,
contains was our comparison type. This comparison type must match one of the comparison type functions listed on this page.
On top of all of the methods listed below, every
Scan instance has all of the methods that a
Condition instance has. This means you can use methods like
lt and more.
Please check the Condition documentation to find the rest of the methods you can use with Scan.
This will execute the scan you constructed. If you pass in a callback the callback function will be executed upon completion passing in an error (if exists), and the results array. In the event you didn't pass in a callback parameter, a promise will be returned that will resolve to the results array upon completion.
The extra properties attached to the array are:
|In the event there are more documents to scan in DynamoDB this property will be equal to an object that you can pass into |
|The count property from DynamoDB, which represents how many documents were returned from DynamoDB. This should always equal the number of documents in the array.|
|How many documents DynamoDB scanned. This doesn't necessarily represent how many documents were returned from DynamoDB due to filters that might have been applied to the scan request.|
|How many times Dynamoose made a scan request to DynamoDB. This will always equal 1, unless you used the |
|A function that is an alias to |
This function will limit the number of documents that DynamoDB will scan in this request. Unlike most SQL databases this does not guarantee the response will contain 5 documents. Instead DynamoDB will only scan a maximum of 5 documents to see if they match and should be returned. The
count parameter passed in should be a number representing how many documents you wish DynamoDB to scan.
In the event there are more documents to scan in a previous response, Dynamoose will return a key in the
.lastKey property. You can pass that object into this property to further scan documents in your table.
.lastKey property returns a standard (non DynamoDB) object, you can pass a standard object OR DynamoDB object into this function, and it will handle either case.
This function will limit which attributes DynamoDB returns for each item in the table. This can limit the size of the DynamoDB response and helps you only retrieve the data you need. The
attributes property passed into this function should be an array of strings representing the property names you wish DynamoDB to return.
This function uses the
ProjectionExpression DynamoDB property to save bandwidth and not send the entire item over the wire.
This function will run parallel scans on your table. The
parallelScans parameter should be a number representing how many concurrent scans you wish to preform on the table. The results will be merged into a single array, with the
timesScanned properties being summed in the response. In the event there are multiple
lastKey properties these will be merged into an array of objects.
WARNING this action can consume a lot of capacity
Instead of returning the documents in the array this function will cause the scan operation to return a special object with the count information for the scan. The response you will receive from the scan operation with this setting will be an object with the properties
scannedCount, which have the same values as described in
Using this option will save bandwidth by setting the DynamoDB
Select option to
This will cause the scan to run in a consistent manner as opposed to the default eventually consistent manner.
This causes the scan to be run on a specific index as opposed to the default table wide scan. The
index parameter you pass in should represent the name of the index you wish to scan on.
Unlike most other scan functions that directly change the DynamoDB scan request, this function is purely internal and unique to Dynamoose. If a scan result is more than the AWS scan response limit, DynamoDB paginates the results so you would have to send multiple requests. This function sends continuous scan requests upon receiving the response until all documents have been received (by checking and making new requests with the
lastKey property from the previous response). This can be useful if you wish to get all the documents from the table and don't want to worry about checking the
lastKey property and sending a new scan request yourself.
Two parameters can be specified on this setting:
delay- Number (default: 0) - The number of milliseconds to delay between receiving of the response of one scan request and sending of the request for the next scan request.
max- Number (default: 0) - The maximum number of requests that should be made to DynamoDB, regardless of if the
lastKeyproperty still exists in the response. In the event this is set to 0, an unlimited number of requests will be made to DynamoDB, so long as the
lastKeyproperty still exists.
The documents for all of the requests will be merged into a single array with the
scannedCount properties being summed in the response. If you set a maximum number of scan requests and there is still a
lastKey on the response that will be returned to you.