KylianMbappe
KylianMbappe

Reputation: 2407

How to add data to a map in Firebase

Hi I'm simply trying to add a map under the messages parent which contains a 'messageText' field and 'messageSender' field, how do you add values to a map in Firebase?

enter image description here

This is the code, I know it doesn't work but hopefully helps you understand what I'm trying to achieve:

 _firestore.collection('chats').document(chatID.documentID).updateData({
                            ['messages']['messageText']: 'this is message text.',
                            ['messages']['messageSender']: 'this is the sender.',
                          });

Thanks.

Upvotes: 0

Views: 1047

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317467

I think you want something more like this:

 _firestore.collection('chats').document(chatID.documentID).updateData({
    'messages': {
        'messageText': 'this is message text.',
        'messageSender': 'this is the sender.'
    }
});

Upvotes: 1

Related Questions