I have a storage in pallet
pub type Users<T: Config> = StorageMap<_, Blake2_128Concat, T::AccountId, User>;
I need to iterate over all the storage map to check a field data inside the User structure.
Substrate and Polkadot Stack Exchange is a question and answer site for developers building blockchains with the Substrate SDK. It only takes a minute to sign up.
Sign up to join this communityStorageMap contains a function called iter() which returns a Iterator. So you can do something like this :
for (user_account_id, user_data) in Users::<T>::iter() {
// Access the `User` structure using the user_account_id
let user = user_data.ok_or("Error: User data not found")?;
// Now you can check the field data inside the `User` structure
if user.some_field == SomeValue {
// Do something with the user's data
}
}