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

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.

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

Have to essentially null check like this:

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

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

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

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

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.