Aerospike Chat


#1

Hello, i would like to create a online chat room(s) for our client. The structure is: namespace: chat set: [room id] key: [microtimestamp]

There is no problem with record creation, but i am not able to write proper query to get last 30 records inserted.

       var statement = {};
	
	if (last_id != null) {
		statement.filters = [aerospike.filter.range('created', last_id, 99999999999999)];
	}
	
	var results = [];
	
	var query = client.query('chat', objectId);
	var stream = query.execute();
	
	stream.on('data', function(result) {
		
		var id = result.meta.key;
		result = result.bins;
		result.id = id;
		
		results.push(result);
	});
	stream.on('error', function(error) {
		okCb();
	});
	stream.on('end', function(end) {
		okCb(results);
	});

Can you please help me? Thank you


#2

Hi Daniel,

I see that you’re filtering only if last_id is not null but statement is never passed to client.query('chat', objectId); — so the code as is will always return all records in chat >> objectId set.

Is that what you’re experiencing and referring to? If not, please share more info with regards to:

  • Expected result vs actual result you’re seeing with your data set
  • Secondary index(es) you’ve created
  • If there are any errors being output in the console or log

Thanks!

Dash


#3

Thank you for your answer. Now i am passing the filter into statement. The problem is that i am unable to get records in ordered list. I use bin “created” (micro time stamp) as index (i am not sure how to use it properly) and as a key. I need last 30 records only.


#4

Hi Daniel,

For ordered list, we’d recommend using Aerospike’s Large Ordered List. IMP to note: It is currently (as of version 1.0.30) not available in our Node.js client but we’re actively working on adding it. In the meantime, you can read more about it here - https://www.aerospike.com/docs/guide/llist.html

I hope this helps.