# Storage write rejected - version check failed

**URL:** <https://forum.heroiclabs.com/t/storage-write-rejected-version-check-failed/2496>\
**Category:** Runtime Framework\
**Tags:** typescript, storage, server-framework\
**Created:** [April 5, 2022, 4:38am UTC](https://forum.heroiclabs.com/t/storage-write-rejected-version-check-failed/2496 "2022-04-05T04:38:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lightning](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/lightning/32/1069_2.png) [@lightning](https://forum.heroiclabs.com/u/lightning)\
**Post date:** [April 5, 2022, 4:38am UTC](https://forum.heroiclabs.com/t/storage-write-rejected-version-check-failed/2496/1 "2022-04-05T04:38:09Z")

</div>

Hi there,  
I am trying to set up data on the Nakama runtime start up by following [this tutorial](https://heroiclabs.com/docs/nakama/tutorials/remote-configuration/), but I am getting the error

```auto
Storage write rejected - version check failed

```

when calling

```auto
nk.storageWrite(<writeObjects>)

```

My code looks as such, where `TREASURES` is a list of my `Treasure` class defined elsewhere:

```auto
const writeObjects: nkruntime.StorageWriteRequest[] =
        TREASURES
            .map(treasure => {
                // create a write request object for each Treasure
                const writeRequest: nkruntime.StorageWriteRequest = {
                    userId: "00000000-0000-0000-0000-000000000000",
                    collection: TREASURES_COLLECTION_NAME,
                    key: `${treasure.treasureId}`,
                    permissionRead: TREASURES_PERMISSION_READ,
                    permissionWrite: TREASURES_PERMISSION_WRITE,
                    value: treasure,
                };
                return writeRequest;
            });
try {
        nk.storageWrite([...writeObjects]);
    } catch (error) {
        logger.error('Treasures storageWrite error: %q', error);
        throw error;
    }

```

I saw a [previous post](https://forum.heroiclabs.com/t/storage-write-rejected-how-to-design-rpcs-with-regards-to-storage-object-write-read-version/2121) where it was suggested to take out the `version` attribute from the `nkruntime.StorageWriteRequest`, but as you can see from my snippet, I do not have the optional `version` attribute on my request objects 😢

I would like to be able to do `version: "*"`, as it says in the documentation that it will only create a storage object if it does not exist in the database - which is what I truly want.

How can I

1. write objects to the database in this manner
2. use the `version: "*"` attribute in my storage write request object to only create these game artifacts once?

Any help is welcome and appreciated.  
Thank you!

1. Versions: Nakama `3.10.0`, Docker, Unity 2021.1.11f
2. Server Framework Runtime language: TS/JS
3. Cockroach DB image version: `cockroachdb/cockroach:latest-v21.2`

---

<div class="post-metadata">

**Author:** ![ftkg](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/ftkg/32/1180_2.png) [@ftkg](https://forum.heroiclabs.com/u/ftkg)\
**Post date:** [April 5, 2022, 1:42pm UTC](https://forum.heroiclabs.com/t/storage-write-rejected-version-check-failed/2496/2 "2022-04-05T13:42:44Z")

</div>

Hi @lightning, are you running this concurrently and do you have contention on these objects?

This error might happen if you are doing non-OCC concurrent writes to the same object, and it’s something we will improve in the future.

As for your second question, you can just add `version: "*"` to your write, and it will return an error if it already exists.

---

<div class="post-metadata">

**Author:** ![lightning](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/lightning/32/1069_2.png) [@lightning](https://forum.heroiclabs.com/u/lightning)\
**Post date:** [April 5, 2022, 4:21pm UTC](https://forum.heroiclabs.com/t/storage-write-rejected-version-check-failed/2496/3 "2022-04-05T16:21:00Z")

</div>

Hi @ftkg !  
Thank you for your quick reply 😄

How do I know if I am doing “non-OCC” concurrent writes to the same object?

I am following [the guide provided in the documentation](https://heroiclabs.com/docs/nakama/server-framework/setup/typescript/) to set up my project and make these database calls. I’m _fairly_ certain I did not change any configuration other than what was outlined.

If I am doing non-OCC concurrent write to the same object, how do I _ **not** _? 😆

Thank you!

---

<div class="post-metadata">

**Author:** ![ftkg](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/ftkg/32/1180_2.png) [@ftkg](https://forum.heroiclabs.com/u/ftkg)\
**Post date:** [April 7, 2022, 11:49am UTC](https://forum.heroiclabs.com/t/storage-write-rejected-version-check-failed/2496/4 "2022-04-07T11:49:09Z")

</div>

I think you need to basically check if you’re calling this function multiple times and if they may be running at the same time. 🙂

---

<div class="post-metadata">

**Author:** ![lightning](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/lightning/32/1069_2.png) [@lightning](https://forum.heroiclabs.com/u/lightning)\
**Post date:** [April 16, 2022, 6:53am UTC](https://forum.heroiclabs.com/t/storage-write-rejected-version-check-failed/2496/5 "2022-04-16T06:53:36Z")

</div>

thank you, @ftkg

i figured out that the example code from the documentation was throwing an error, where `version: '*'` throws an error if something is already created - as you stated.

after taking out the code that throws an error, the data goes in the database perfectly.

```auto
const writeObjects: nkruntime.StorageWriteRequest[] =
        TREASURES
            .map(treasure => {
                // create a write request object for each Treasure
                const writeRequest: nkruntime.StorageWriteRequest = {
                    userId: "00000000-0000-0000-0000-000000000000",
                    collection: TREASURES_COLLECTION_NAME,
                    key: `${treasure.treasureId}`,
                    permissionRead: TREASURES_PERMISSION_READ,
                    permissionWrite: TREASURES_PERMISSION_WRITE,
                    value: treasure,
                };
                return writeRequest;
            });
try {
        nk.storageWrite([...writeObjects]);
    } catch (error) {
        logger.error('Treasures storageWrite error: %q', error);
        // there was an error being thrown here... removed this
    }

```

thanks!
