What I'm trying to achieve in here is to update a given set of documents that contain a given set of fields, either one, another or both.
I have two questions actually for this matter...
Can MongoDB process fields that aren't present in the document being processed? Like what I'm trying to achieve here, sum two fields, and if one is null just sum 0.
And the other one is the error that I'm getting in the query...
db.getCollection('my_collection').update({'$or': [{
'a_field': 1}, {
'another_field': 1
}
]},
{'$set': {
'another_field': {
'$sum': [
'$a_field', '$another_field'
]
}
},
'$unset': {'a_field': ''}})
Giving me the following error...
The dollar ($) prefixed field '$sum' in 'another_field.$sum' is not valid for storage.