I'm building an app using AngularJS, MongoDB and NodeJS. My app uses the Mongolab REST API for CRUD operations. I'm also using Google Chrome Developer Tools for debugging.
Until today, my Update operations on mongo were working fine on both Chrome and Firefox (that I use occasionally) but after Chrome updated automatically, the updates fail and I have this error :
TypeError: Cannot assign to read only property '_id' of {"$inc":{"count":1},"$set":{"messages":[{"unread":false,"flagged":false}]}}
at http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.9/angular.js:409:18
I have this error only on Chrome, Firefox shows no error at all and the update is successful. Using strict mode in my angular module the update itself is done using this :
Resource.prototype.$update = function (queryJson,successcb, errorcb) {
var params = angular.isObject(queryJson) ? JSON.stringify(queryJson) : {},
httpPromise = $http.put(url + "/" + this.$id(), angular.extend(params, this, {_id:undefined}), {params:defaultParams});
return thenFactoryMethod(httpPromise, successcb, errorcb);
};
Where :
var queryJson = { "$inc": {"count":1} , "$set" : {"messages": message} };
I'm not sure if it's because of the update on Chrome or something else.
Has anyone come across something like this? Any help will be greatly appreciated.
Note: {_id:undefined} is just a way of removing the _id property from the object. MongoLab requires id of an object to update to be sent as part of the URL and not as part of data sent via PUT.
Another way of doing it :
var objCopy = angular.copy(this) ;
if (objCopy._id)
delete objCopy["_id"] ;
httpPromise = $http.put(url + "/" + this.$id(), angular.extend(params, objCopy), {params:defaultParams}) ;