My service is structured as follows (with variables removed):
angular
.module('app')
.factory('Employee', function($resource) {
return $resource("https://api.mongolab.com/api/1/databases/:dbName/collections/:collectionName/:id",
{apiKey: apiKey, dbName: dbName, collectionName: collectionName},
{ update: { method: 'PUT' } });
});
The add/edit form controller for creating/retrieving an employee looks like this:
if($stateParams.id === "add") {
$scope.employee = new Employee();
} else {
$scope.employee = Employee.get({id: $stateParams.id});
}
On the form, there is a Save
button with the following function attached to it:
if($scope.employee._id) {
$scope.employee.$update({id:$scope.employee._id});
} else {
$scope.employee._id = $scope.employee.jmbg;
$scope.employee.$save();
}
While the "Add" functionality works smoothly, updating an existing employee results in the following error:
400 Bad Request - Invalid object { "_id" : "000" , "jmbg" : "000" , "name" : "Bilbo" , "surname" : "Hagins" , "email" : "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3e5c575c577e5c575c57105d5153">[email protected]</a>" , "$promise" : { } , "$resolved" : true} - Document field names can't start with '$' (Bad Key: '$promise')
Even though my $scope.employee
does contain these fields, this is the first time I've encountered such an issue. I have utilized similar functionalities in other projects without any errors, including one that uses the same MongoLab API backend.
Note that no configuration has been set up within my angular app.