# How to access ?V from a Trie.get() function

**URL:** <https://forum.dfinity.org/t/how-to-access-v-from-a-trie-get-function/11420>\
**Category:** Developers\
**Created:** [March 10, 2022, 11:26am UTC](https://forum.dfinity.org/t/how-to-access-v-from-a-trie-get-function/11420 "2022-03-10T11:26:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rbole](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/rbole/32/1334_2.png) [@rbole](https://forum.dfinity.org/u/rbole)\
**Post date:** [March 10, 2022, 11:26am UTC](https://forum.dfinity.org/t/how-to-access-v-from-a-trie-get-function/11420/1 "2022-03-10T11:26:26Z")

</div>

Hi,  
I have a Trie with some data. I would like to query the Trie with the get function.  
e.g.

let oldNftItem = Trie.get(nftBelogsTo, key(nftId), Nat32.equal);

When I would like to access that data, then I receive an error.  
D.print(debug\_show(oldNftItem.tokenId));

type error [M0070], expected object type, but expression produces type ?Nft

My question is how can I access the value of oldNftItem.tokenId and work further witch it ?

Thanks for any hint.

---

<div class="post-metadata">

**Author:** ![Gekctek](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/gekctek/32/6863_2.png) [@Gekctek](https://forum.dfinity.org/u/Gekctek)\
**Post date:** [March 10, 2022, 1:18pm UTC](https://forum.dfinity.org/t/how-to-access-v-from-a-trie-get-function/11420/2 "2022-03-10T13:18:40Z")

</div>

It’s an Option of the value (?Nft) vs the value (Nft)

> **[Internet Computer | Documentation](https://smartcontracts.org/docs/base-libraries/Option.html)**
>
> Documentation for the internet computer.

Have to essentially null check like this:

```auto
let oldNftItem = Trie.get(nftBelogsTo, key(nftId), Nat32.equal);
switch oldNftItem {
  case null {
    // Handle null case
  };
  case (?item) {
    D.print(debug_show(item.tokenId))
  }
}

```

---

<div class="post-metadata">

**Author:** ![rbole](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/rbole/32/1334_2.png) [@rbole](https://forum.dfinity.org/u/rbole)\
**Post date:** [March 10, 2022, 2:52pm UTC](https://forum.dfinity.org/t/how-to-access-v-from-a-trie-get-function/11420/3 "2022-03-10T14:52:50Z")

</div>

OK, thank you very much your solution works very well .

---

<div class="post-metadata">

**Author:** ![jzxchiang](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/jzxchiang/32/2592_2.png) [@jzxchiang](https://forum.dfinity.org/u/jzxchiang)\
**Post date:** [March 10, 2022, 11:48pm UTC](https://forum.dfinity.org/t/how-to-access-v-from-a-trie-get-function/11420/4 "2022-03-10T23:48:56Z")

</div>

If you want to assert when the return value is null, then you can use this hacky solution to replace the switch statement:

```auto
let ?oldNftItem = Trie.get(nftBelogsTo, key(nftId), Nat32.equal);

```

---

<div class="post-metadata">

**Author:** ![rbole](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/rbole/32/1334_2.png) [@rbole](https://forum.dfinity.org/u/rbole)\
**Post date:** [March 11, 2022, 5:45am UTC](https://forum.dfinity.org/t/how-to-access-v-from-a-trie-get-function/11420/5 "2022-03-11T05:45:58Z")

</div>

thanks, but I`m surprised that there so no easy way to access a value from a Trie storage element, because a Trie seems to me as a good way to store and filter large amount of records.
