# Find All without PK

**URL:** <https://discuss.aerospike.com/t/find-all-without-pk/9928>\
**Category:** General Discussion\
**Tags:** query, primarykey\
**Created:** [December 21, 2022, 1:16pm UTC](https://discuss.aerospike.com/t/find-all-without-pk/9928 "2022-12-21T13:16:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![shulamitbarron](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/shulamitbarron/32/1992_2.png) [@shulamitbarron](https://discuss.aerospike.com/u/shulamitbarron)\
**Post date:** [December 21, 2022, 1:16pm UTC](https://discuss.aerospike.com/t/find-all-without-pk/9928/1 "2022-12-21T13:16:59Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Albot](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/albot/32/2076_2.png) [@Albot](https://discuss.aerospike.com/u/Albot)\
**Post date:** [December 21, 2022, 5:14pm UTC](https://discuss.aerospike.com/t/find-all-without-pk/9928/2 "2022-12-21T17:14:26Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![shulamitbarron](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/shulamitbarron/32/1992_2.png) [@shulamitbarron](https://discuss.aerospike.com/u/shulamitbarron)\
**Post date:** [December 21, 2022, 11:21pm UTC](https://discuss.aerospike.com/t/find-all-without-pk/9928/3 "2022-12-21T23:21:33Z")

</div>

> [@Albot](#):
>
> You can rewrite them with SendKey

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!

---

<div class="post-metadata">

**Author:** ![Albot](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/albot/32/2076_2.png) [@Albot](https://discuss.aerospike.com/u/Albot)\
**Post date:** [December 22, 2022, 10:09pm UTC](https://discuss.aerospike.com/t/find-all-without-pk/9928/4 "2022-12-22T22:09:53Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![pgupta](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/pgupta/32/2351_2.png) [@pgupta](https://discuss.aerospike.com/u/pgupta)\
**Post date:** [December 23, 2022, 12:24am UTC](https://discuss.aerospike.com/t/find-all-without-pk/9928/5 "2022-12-23T00:24:12Z")

</div>

[scanCallback](https://javadoc.io/static/com.aerospike/aerospike-client/6.1.5/com/aerospike/client/ScanCallback.html#scanCallback-com.aerospike.client.Key-com.aerospike.client.Record-)([Key](https://javadoc.io/static/com.aerospike/aerospike-client/6.1.5/com/aerospike/client/Key.html) key, [Record](https://javadoc.io/static/com.aerospike/aerospike-client/6.1.5/com/aerospike/client/Record.html) 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:

```auto
RecordSet rs = client.query(qp, stmt); //qp is QueryPolicy, stmt is Statement
int nCount = 0;
while(rs.next()){
    Key k = rs.getKey();  
    Bin newBin = new Bin("newBin", nCount);
    nCount++;
    client.put(null, k, newBin);
}

```

---

<div class="post-metadata">

**Author:** ![system](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/system/32/2274_2.png) [@system](https://discuss.aerospike.com/u/system)\
**Post date:** [March 17, 2023, 12:24am UTC](https://discuss.aerospike.com/t/find-all-without-pk/9928/6 "2023-03-17T00:24:28Z")

</div>

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