tajihiro
tajihiro

Reputation: 2443

How to update the part of data without all data in Firebase with Flutter

I'm from following issue.

Add nested data in Firestore by flutter

I would like to update only car1 name and img_url. I succeed update car1 name and img_url. However details are disappeared without data.

I would like to know how to update the part of data.

_firestore.collection('members').document(${loginUser.uid}).updateData({
    'cars': {
    'car1': {
        'name': name,
        'img_url': 'https://www.xxx.xxx/xxx.png',
        'details': {
            'type': carType,
        }
    }
  }

How can I do that. Please give me advice. Thanks.

Upvotes: 0

Views: 236

Answers (1)

Shubham Gupta
Shubham Gupta

Reputation: 1997

You can use setData with merge:true

_firestore.collection('members').document(${loginUser.uid}).setData({
'cars': {
  'car1': {
      'name': name,
      'img_url': 'https://www.xxx.xxx/xxx.png',
      }
    },
  },
  merge:true,
);

Upvotes: 2

Related Questions