Ionic/Storage doesn't remove key/value pairs

  public async deleteConversation(user: Contact): Promise<void> {
    this.conversationStorage.remove(user.id);

    const messages = await this.conversationStorage.get('conversations');
    console.log(messages); //<--nothing deleted
  }
    this.conversationStorage.get('conversations').then((conversation: Conversation): void => {
       if (conversation.id === user.id) {
         delete conversation.id;
       }
     });

still nothing deleted

message.service

export class ChatService {
  private conversationStorage: Storage;
   public constructor () {

    this.conversationStorage = new Storage({
      name: 'messageStorage',
      storeName: '_messageStorage',
    });  // note you can't declare Storage in constructor if you want to create an instance

  }
// the function listed above

remove also returns a Promise, which it looks like you are ignoring. Also, I don’t understand why you are manually instantiating Storage.

1 Like

Yea, just to add on, it’s in the docs here: https://ionicframework.com/docs/building/storage#remove-

Returns a promise that resolves when the value is removed

it resolves once it is removed. I don’t need to consume it.

I’m sorry if I sound sarcastic about this, but, as you can see from the implementation above I tried that.

I solved it. The only way to do that is to store EACH conversation as it’s own key within the Storage instance. Before when I used storage.keys() I would only get 'conversations' and the value of that would be a series of key/value pairs. Which, looking at it now is not the best way to handle it. Instead what I had to do with the storage instance is dynamically create keys based on the users id for example. from there I can use storage.remove()