Thank you @meher for your swift response. It really helps! However, not the exact thing I was looking for – nonetheless, it is of great help in many ways… May be, I couldn’t explained better in the above comment.
Here is what exactly I am looking for your suggestions:
A simple scalar data type set (like typical Relational databases). Please look at this set format:
+------------+------+-----------+--------------+-----------+
| pk | sort | userId | played | contestId |
+------------+------+-----------+--------------+-----------+
| 1658851106 | 4 | 100000052 | "Basketball" | 1500012 |
| 1658851283 | 9 | 100000050 | "Cricket" | 1500017 |
| 1658851006 | 2 | 100000051 | "Football" | 1500009 |
| 1658851058 | 3 | 100000052 | "Football" | 1500011 |
| 1658851229 | 7 | 100000050 | "Cricket" | 1500015 |
| 1658851171 | 6 | 100000052 | "Basketball" | 1500014 |
| 1658851151 | 5 | 100000052 | "Basketball" | 1500013 |
| 1658851250 | 8 | 100000050 | "Cricket" | 1500016 |
| 1658850954 | 1 | 100000050 | "Cricket" | 1500000 |
| 1658851315 | 10 | 100000051 | "Tennis" | 1500018 |
+------------+------+-----------+--------------+-----------+
Node js put query:
const pKey = Math.floor(+new Date() / 1000); //instance epoc timestamp
const sort = define.sort; //for sort count we maintained exclusively different namespace which is incremented everytime new records are added to avoid UDF or complex query
const userId = defined.userId; //Secondary Index
const sportName = defined.sportName; //Secondary Index
const contestId = defined.contestId;
const key = new Aerospike.Key('test', 'playedContests', pKey)
let bins = {
pk: pKey,
sort: sort, //sort basically is used to limit records for pagnation
userId: userId,
played: sportName,
contestId: contestId
}
// Write the record
await client.put(key, bins);
Node js get query with filter and sort as per defined sort value (limit range) we have in place:
let query = client.query("test", "playedContests");
query.where(Aerospike.filter.equal("played", "Cricket"));
query.where(Aerospike.filter.range('sort',1, 3))
var stream = query.foreach();
stream.on('data', function (record) {
console.log("Response :: ", record)
//process record
})
This query will only return me 1 record as per in the records table above because sort bin will read only between 1-3 sort (limit range) values, but when you see we have about 4 records where bin (played = cricket)… In large records it’s impossible to filter and then limit with value range (sort bin here) with this logic.
My questions are:
- can we use rank range here? (but here also I am talking about simple scalar data not list or map scan).
- Is there any ordered insert operation for such type of simple scalar data like order record data in sequence as per insertion timestamp ASC order of PK?
- Do you have better suggestions to deal with the data structure to met such requirements?
- 5 bins with 2 secondary index OR 2 bins with 1 map/list data… which is better performant for 70:30 read:write data…
Thank you so much for all the support and suggestions.