Ad
Only Update One Property Of The Collection's Field
Current application logic requires to store user records by years and will look something like:
balanceRecords: {
2017: {
...,
12: { ... }
},
2018: {
...,
12: { ... }
},
2019: {
...,
8: { ... }
}
}
I've tried to update the document by ID inside the users
collections
// year --> returned from the for loop operation from [2017, 2018, 2019]
firebaseDb.collection(`users`).doc(fyuAqykYpMVnB0h9grdznZgEcaU2)
.update( personalData: {
[year]: {}
})
.then(...)
.catch(...)
Doing this I came to conclusion that each time I just overwrite the balanceRecords
fields inside the document. Is it in general possible to update just a property of deep-nested field or it's expected that sub-collections
are used instead?
Ad
Answer
First of all, doc(``)
doesn't help anything. Just remove that.
You can use dot notation to update a deep property. I changed some of your sample code because it had syntax errors and apparently was updating a different property than the one you highlighted.
firebaseDb.collection('users').doc('fyuAqykYpMVnB0h9grdznZgEcaU2')
.update( `balanceRecords.${year}`: {
// whatever properties you want
})
Ad
source: stackoverflow.com
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
Ad