The stable hashmap issue


I’m running (probably a few months later than everyone lol) into the notorious “Hashmaps can’t be stable” issue.

Like many, I’d love to avoid having to manage pre/post upgrade scripts, so I’m looking into using @ZhenyaUsenko’s motoko-hash-map.

(if anyone thinks it’s not the best decision, please speak up!)

My questions are:

  • there’s no mops package, right ? I’ve read I should use import Map "motoko-hash-map/src/Map/Map" to use it but how do I clone it into my project before (sorry I’ve only ever used npm packages… :flushed:)
  • does anyone have public examples of how they’re using it ?
  • I currently have Hashmaps in my main Hashmap. Do I have to use the library for all of them or only for the main (outtermost) one ?


It’s pretty easy to get started with mops! I’d say to give it a shot

1 Like

Oh sorry I didn’t realize it was now a mops package (relied on this old comment). Great! Thanks @kpeacock

Any clues for the other questions? :slight_smile:

  1. I know I’ve used it before somewhere, but give it a shot just using the docs!

  2. If you want the map to be stable, you will need all of the fields to use stable types, so you may want to switch to a Map across the board. Try using it in a simple example first to get a sense of it and if you like it before committing to the full rework

It was published to mops quite a while ago Mops • Motoko Package Manager

The detailed documentation is there, but if you have any questions, feel free to ask.

To be able to store it in a stable variable, you’ll need to replace the nested hashmaps as well.

1 Like