There are many different ways to save a set of data / map / DB via Motoko. For example:
On Base:
Array, AssocList, Buffer, HashMap, List, RBTree, Trie, TrieMap
Other Mops:
vector, swb, stable-buffer, rxmodb, CanDB, stableheapbtreemap
and possibly more…
I noticed that thare are a lot of developers strugeling, including myself, to pick the best map/db prectice for a Motoko project. On the documentation page of Motoko (here) I can find some basic information about an module.
Is it possible to give the developers community an overview of the differences between the maps and how they work to store data? What the advantages and disadvantages are of a module and which one is preferred for some cases (best practices).
In Motoko, there are stable data structures can be used with the stable keyword to automatically persist that data across upgrades, and class based data structures that are not stable, meaning that you have to write your own serialization logic to persist them across upgrades.
My recommendation is to use stable data structures in Motoko. Here are a few of the most popular that should get you pretty far:
stableheapbtreemap - BTree - a balanced, sorted tree based data structure. Been running in production for a year and half with no issues. Use it if you want to be able to search & scan/paginate. This library sits underneath and powers CanDB.
map - performant hash map/set. Stable for over a year now?
For general logic inside of a function, I’d still recommend using the Motoko base library for primitives (Nat, Int, Iter, Option, etc.) and temporary logic, but most of the data structures in the Motoko base library were written a long time ago and haven’t been updated in awhile. Many of the libraries in mops are now more fully featured and performant than those in base.
Mops makes it super easy to install specific modules, so I’d recommend starting at mops.one and searching for a specific package/use case.
Have a question about a library? Ask it in these forums or on the library’s GitHub repo and that should help provide answers with respect to its current support.