Search code examples
node.jsaerospikenosql

Get range of records based on key - Aerospike


I'm fairly new to Aerospike. Been checking the API docs, but I'm having trouble getting a clear process. I'm using the Node Client.

I have records: Ex:

key: {ns:'cache', set:'fieldA', key:'1437777737287'}

value: [1,2,3,4,5,6,7,8,9]

I want to make a query that will fetch records with matching ns, set and keys from 1437777737277 to 1437777737297, for example.

What would be the best approach ?

Thanks


Solution

  • You can use a query with range filters:

    var filter = aerospike.filter;
    var query = client.query('cache', 'fieldA', {filters: [filter.range('id', 1437777737277, 1437777737297)]});
    
    var queryStream = query.execute();
    queryStream.on('data', function (rec) {
      console.log(rec);
    });
    
    queryStream.on('error', function (err) {
      console.log(err);
    });
    
    queryStream.on('end', function () {
      console.log('the end')
    });