MongoDB - "Prefixed dollar ($) field" $$ hashKey "in field" Field name ". $$ hashKey \ not valid for storage. '"
I get the above error for the field when trying to update the document timesToDisplay
.
MongoDB version 2.6.7.
The whole model:
msg = {
'name': '',
'template': '',
'displayDurInMilliSec': 0,
'timesToDisplay': [],
'images': [],
'texts': [],
'screen': []
}
I am guessing I am getting the same error with other fields of array 3.
I tried using $set
it but threshold was getting the same error.
Code:
function updateMessage(msg) {
var conditions = {_id: msg._id}
, update = { 'name': msg.name,
'template': msg.template,
'displayDurInMilliSec': msg.displayDurInMilliSec,
'timesToDisplay': msg.timesToDisplay,
'images': msg.images,
'texts': msg.texts,
'screen': msg.screen
}
messageModel.update(conditions, update, callback);
function callback(err, numAffected) {
if (!err) console.log(numAffected)
else console.log(err)
}
}
EDIT: The parameter msg
is the document itself:
{ _id: '557d58abd54955480db6694f',
name: 'msg99',
timesToDisplay: [ { startDate: '2015-06-19T21:00:00.000Z',
'$$hashKey': 'object:214',
endDate: '2015-06-25T21:00:00.000Z',
daysOfTheWeek: [Object],
startTimeOfDay: '11',
endTimeOfDay: '13' } ],
images: [],
texts: [],
screen: [ 1 ],
'$$hashKey': 'object:54',
displayDurInMilliSec: '40189',
template: 'templates/Template2.html' }
source to share
The field is $$hashkey
added by AngularJS when working with ngRepeat or ngOptions. In the case of ngRepeat, you can change the repeat line by appending to it track by $index
. To use ngOptions, you will have to filter this field yourself. AngularJS provides a quick solution to its filtering: angular.toJson
. This will filter out all fields with two dollar signs. Check the documentation .
I understand this is not MongoDB's answer, but this particular error ($$ hashkey) is usually AngularJS related.
source to share