Find All without PK

If at the time of record creation I didn’t set the key policy to SEND the KEY, and Aerospike stored only the DIGEST.

Now I set the policy to SEND the KEY.

But when I do findAll - I get an exception “Id must not be null!” because there are few records that stored before I set the sendKey to true.

What can I do with them?

You can ignore them. You can delete them. You can rewrite them with SendKey. I don’t think there is anything stopping you ? There is no way to recover the original primary key from just the digest though, so unless its stored somewhere or you can rewrite all your data it is lost.

How are you querying? Can you give us a snippet? Maybe this is something I’m not understanding thats baked into the language?

Hi, Thanks for your answer.

Here is the case: I don’t have the ids of the documents (this is some userIds).

My code in JAVA. If I need to get a specific document for a user - I can get id with getByIds - client.get(null, keys). But I need to update all the documents (again - I don’t have the list of ids).

So I try to do scanAll and loop over the result - but we have documents without an id So when I try to save the updated document - it failed “Id must not be null!”

How can I save a ducument that I just fetch but there is no PK.

Thanks a lot!

Can you show us a code snippet with the scan all? Surely you can detect the record in the scancallback, determine if it has the Id key, and handle it differently?

scanCallback(Key key, Record record) - provides the key object - which you can use to update the record. It has the digest - so even if you don’t know the user key, you can still update that record.

Likewise, in the latest server, you can use:

RecordSet query(QueryPolicy policy, Statement statement)

Execute query on all server nodes and return record iterator.

This returns RecordSet … which has getKey() method. For example:

RecordSet rs = client.query(qp, stmt);  //qp is QueryPolicy, stmt is Statement
int nCount = 0;
    Key k = rs.getKey();  
    Bin newBin = new Bin("newBin", nCount);
    client.put(null, k, newBin);
1 Like

This topic was automatically closed 84 days after the last reply. New replies are no longer allowed.