Deployd Hi when I post to deployd I get this strange error in the console Object {name: "MongoError", mess...">
Deployd - javascript πŸ‘¨πŸ½ πŸ‘‡πŸΎ πŸ‘©β€β€οΈβ€πŸ’‹β€πŸ‘©

$$ hashKey must not start with '$' Deployd

Hi when I post to deployd I get this strange error in the console

Object {name: "MongoError", message: "key $$hashKey must not start with '$'", status: 400}

      

code

 dpd.timesheetsdone.post({
      "projectId": $scope.projectId ,
      "formandSig":  $scope.signature,
      "timesheets": $scope.timesheets

    }, function (result, err) {
      if (err) return console.log(err);
      console.log(result, result.id);
    });

      

project id and signature is a simple string, schedules are an array

if i replace scope.timesheets with

  [
    {
        "projectId": "1000",
        "date": "2015-05-15T22:00:00.000Z",
        "start": "25200"
    }
]

      

it works.

onsole.log (scope.timesheet ... returns an object with the same values ​​+ and hash key

+3


source to share


2 answers


Removed parsing sheets of hash keys in JSON Not sure if this is the correct / best way to remove hash keys?



      $scope.sign = function() {
   var sheets = angular.toJson($scope.timesheets);
   var sheets = JSON.parse(sheets);
    dpd.timesheetsdone.post({
      "projectId": $scope.projectId ,
      "formandSig":  $scope.signature,
      "timesheets": sheets

    }, function (result, err) {
      if (err) return console.log(err);
      console.log(result, result.id);
    });
  }

      

+2


source


Angular automatically adds $$hashKey

to all objects in your array $scope.timesheets

. You can get rid of them by doingangular.toJson($scope.timesheets)

so your post will look like this:



 dpd.timesheetsdone.post({
  "projectId": $scope.projectId ,
  "formandSig":  $scope.signature,
  "timesheets": angular.toJson($scope.timesheets)
  ...

      

+3


source







All Articles