I need to remove a sub field from all the elements in a collection using mongoose, I created a JS script for this few weeks ago and as far as I can recall it worked back then, but now seems like is not working anymore. What I was basically doing is:
Collection.find({'supField.myfield': {$exists: true}})
.then(function(dataList){
var dataId = dataList[0]._id;
// some other stuff here
return Collection.update({_id: dataId}, {'$unset' : {'supField.myfield':1}})
})
.then(function(updated){
console.log(updated) // dumps 0
})
If requiring mongoose i set the debug flag (require('mongoose').set('debug', true)
) it dumps no update query.
This behavior is strange and I'm afraid it's been caused by some update, but it can also be some mistake on my side.
[EDIT] Apparently is a problem connected with the fact that I'm trying to update a subfield and not a normal field. But still I got no evidence of this being a problem