# Storage\_write(obj) vs pcall(storage\_write, {obj}

**URL:** https://forum.heroiclabs.com/t/storage-write-obj-vs-pcall-storage-write-obj/2397
**Category:** Runtime Framework
**Tags:** server-framework, storage, lua
**Created:** [February 23, 2022, 8:02pm UTC](https://forum.heroiclabs.com/t/storage-write-obj-vs-pcall-storage-write-obj/2397 "2022-02-23T20:02:30Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Omee](https://avatars.discourse-cdn.com/v4/letter/o/8dc957/32.png) [@Omee](https://forum.heroiclabs.com/u/Omee)
#### Post date: [February 23, 2022, 8:02pm UTC](https://forum.heroiclabs.com/t/storage-write-obj-vs-pcall-storage-write-obj/2397/1 "2022-02-23T20:02:30Z")

</div>

Hi,

I’m new to Nakama, and I’m really impressed with it so far.

I’m having a problem with a server side RPC written in Lua.  
I try to write some data to the object storage, it works fine if I use a pcall(nk.storage\_write, { obj }), but if I try nk.storage\_write(obj) as it shows in the docs the object doesn’t get written to the database.

The same happens when trying to read with storage\_read. I’ve included some code snippets below.

```auto
    local object = {
        collection = "player",
        key = "data",
        user_id = user_id
    }  
    local objects = nk.storage_read(object)

    local object = {
        collection = "player",
        key = "data",
        user_id = user_id
    }
    local success, objects = pcall(nk.storage_read, { object })

```

The pcall returns the object correctly, the nk.storage\_read() returns nothing.

What am I doing wrong?

Thanks.

---

<div class="post-metadata">

### Author: ![flavio](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/flavio/32/2161_2.png) [@flavio](https://forum.heroiclabs.com/u/flavio)
#### Post date: [February 23, 2022, 10:46pm UTC](https://forum.heroiclabs.com/t/storage-write-obj-vs-pcall-storage-write-obj/2397/2 "2022-02-23T22:46:18Z")

</div>

Hello @Omee,

Both functions, [storage\_write](https://github.com/heroiclabs/nakama/blob/8b6c2821c6bba35d63a745cc5568ae6a7e348609/server/runtime_lua_nakama.go#L5403) and [storage\_read](https://github.com/heroiclabs/nakama/blob/8b6c2821c6bba35d63a745cc5568ae6a7e348609/server/runtime_lua_nakama.go#L5262), were written to accept `lua tables` so I believe it’s an inconsistency in the documentation. Could share the links to the snippets you based your code on?

---

<div class="post-metadata">

### Author: ![Omee](https://avatars.discourse-cdn.com/v4/letter/o/8dc957/32.png) [@Omee](https://forum.heroiclabs.com/u/Omee)
#### Post date: [February 23, 2022, 11:54pm UTC](https://forum.heroiclabs.com/t/storage-write-obj-vs-pcall-storage-write-obj/2397/3 "2022-02-23T23:54:18Z")

</div>

> **[Function Reference - Heroic Labs Documentation](https://heroiclabs.com/docs/nakama/server-framework/function-reference/)**
>
> Documentation for the Nakama realtime and social server for games and apps.

Under the Storage Engine section. Change the code examples to Lua and you can see a read and write using nakama.storage\_read and nakama.storage\_write.

Ok, now that I’ve looked at the examples more closely, I can see that the objects should be nested in another Lua table like so:

```auto
local object = {
        collection = "player",
        key = "data",
        user_id = user_id
    }  
    local objects = nk.storage_read( { object } )

```

That code works. I’m new to Lua, so I’m not sure if that is something that is obvious in the documentation or if it could be a bit clearer? The examples in the documentation all involve reading and writing passing in multiple objects as the parameter. Maybe an example passing in a single object would be beneficial?

Thanks for the quick response!
