In Aerospike, is it possible to do a scan with a limit in the Node client?



I was wondering, is there any way we can perform a scan but with a limit in Nodejs? or for example, grab N records randomly, or last N records modified?

I started using scan as per: which is really useful for us but as a set can have many (many) records, it would be good to limit the quantity of them somehow, as we need just some records to make sampling (not the whole database).



Hi @fdnieves

In aerospike, the data is distributed randomly into 4096 partitions. You can scan a percentage of data from each partitions. API cannot specify the number of records for scan. To specify the percentage,

var options = {
   percent: 10
var stream = aeroclient.query(namespace, set, options);

stream.on('data', callback);
stream.on('error', callback_err);
stream.on('end', callback_end);

For API reference please refer here


This is useful, thanks a lot !


Hello, one question because the code you sent to me raises an error:

Oct 30 2015 20:24:38 GMT: ERROR(30677) [] [ParseScanPercent] - scan percentage should be a number

…node_modules/aerospike/lib/aerospike.js:95 var queryObj = this.createQuery(ns, set, options); ^ Error: Scan percentage is not an integer - expected integer value

And this is the code snippet:

var options = {
   percent: 1

var scan = asd_client.query("namespace", "set", options);

var stream = scan.execute();

stream.on('data', process_record);
stream.on('error', callback_err);
stream.on('end', callback_end);

Do you know what is wrong in here?




Apologies for the inconvenience. Latest release should fix this error.




Please let us know whether you were able to upgrade to the latest version of the Aerospike Node.js Client and whether this fixes the error.


Yes, it worked perfectly! Sorry for the delay in my response, thanks :slightly_smiling: