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

**URL:** https://discuss.aerospike.com/t/in-aerospike-is-it-possible-to-do-a-scan-with-a-limit-in-the-node-client/1998
**Category:** Node.js Client
**Created:** [October 14, 2015, 5:02pm UTC](https://discuss.aerospike.com/t/in-aerospike-is-it-possible-to-do-a-scan-with-a-limit-in-the-node-client/1998 "2015-10-14T17:02:20Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![fdnieves](https://avatars.discourse-cdn.com/v4/letter/f/ce73a5/32.png) [@fdnieves](https://discuss.aerospike.com/u/fdnieves)
#### Post date: [October 14, 2015, 5:02pm UTC](https://discuss.aerospike.com/t/in-aerospike-is-it-possible-to-do-a-scan-with-a-limit-in-the-node-client/1998/1 "2015-10-14T17:02:20Z")

</div>

Hello!

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: [http://www.aerospike.com/docs/client/nodejs/usage/scan/scan.html](http://www.aerospike.com/docs/client/nodejs/usage/scan/scan.html) 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).

Thanks!

---

<div class="post-metadata">

### Author: ![gayathri](https://avatars.discourse-cdn.com/v4/letter/g/838e76/32.png) [@gayathri](https://discuss.aerospike.com/u/gayathri)
#### Post date: [October 20, 2015, 10:15am UTC](https://discuss.aerospike.com/t/in-aerospike-is-it-possible-to-do-a-scan-with-a-limit-in-the-node-client/1998/2 "2015-10-20T10:15:01Z")

</div>

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,

```nohighlight
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](https://github.com/aerospike/aerospike-client-nodejs/blob/master/docs/client.md#query)

---

<div class="post-metadata">

### Author: ![fdnieves](https://avatars.discourse-cdn.com/v4/letter/f/ce73a5/32.png) [@fdnieves](https://discuss.aerospike.com/u/fdnieves)
#### Post date: [October 20, 2015, 3:27pm UTC](https://discuss.aerospike.com/t/in-aerospike-is-it-possible-to-do-a-scan-with-a-limit-in-the-node-client/1998/3 "2015-10-20T15:27:37Z")

</div>

This is useful, thanks a lot !

---

<div class="post-metadata">

### Author: ![fdnieves](https://avatars.discourse-cdn.com/v4/letter/f/ce73a5/32.png) [@fdnieves](https://discuss.aerospike.com/u/fdnieves)
#### Post date: [October 30, 2015, 8:27pm UTC](https://discuss.aerospike.com/t/in-aerospike-is-it-possible-to-do-a-scan-with-a-limit-in-the-node-client/1998/4 "2015-10-30T20:27:03Z")

</div>

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

Oct 30 2015 20:24:38 GMT: ERROR(30677) [query.cc:270] [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?

Thanks

---

<div class="post-metadata">

### Author: ![gayathri](https://avatars.discourse-cdn.com/v4/letter/g/838e76/32.png) [@gayathri](https://discuss.aerospike.com/u/gayathri)
#### Post date: [November 3, 2015, 8:39am UTC](https://discuss.aerospike.com/t/in-aerospike-is-it-possible-to-do-a-scan-with-a-limit-in-the-node-client/1998/5 "2015-11-03T08:39:59Z")

</div>

Hi,

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

Thanks.

---

<div class="post-metadata">

### Author: ![Mnemaudsyne](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/mnemaudsyne/32/200_2.png) [@Mnemaudsyne](https://discuss.aerospike.com/u/Mnemaudsyne)
#### Post date: [November 11, 2015, 2:10am UTC](https://discuss.aerospike.com/t/in-aerospike-is-it-possible-to-do-a-scan-with-a-limit-in-the-node-client/1998/6 "2015-11-11T02:10:18Z")

</div>

@fdnieves,

Please let us know whether you were able to upgrade to the [latest version of the Aerospike Node.js Client](http://www.aerospike.com/download/client/nodejs/1.0.53/) and whether this fixes the error.

---

<div class="post-metadata">

### Author: ![fdnieves](https://avatars.discourse-cdn.com/v4/letter/f/ce73a5/32.png) [@fdnieves](https://discuss.aerospike.com/u/fdnieves)
#### Post date: [February 4, 2016, 7:40pm UTC](https://discuss.aerospike.com/t/in-aerospike-is-it-possible-to-do-a-scan-with-a-limit-in-the-node-client/1998/7 "2016-02-04T19:40:38Z")

</div>

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