$$ hashKey不能以'$'Deployd

时间:2015-05-25 13:57:13

标签: javascript ionic deployd

嗨,当我发布到deployd时,我在控制台中得到了这个奇怪的错误

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

 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);
    });

项目ID和签名是一个简单的字符串,时间表是一个数组

如果我用

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

它有效..

onsole.log(scope.timesheet ...返回具有相同值+和散列键

的对象

2 个答案:

答案 0 :(得分:3)

Angular会自动将$$hashKey添加到$scope.timesheets数组中的所有对象。你可以通过angular.toJson($scope.timesheets)

来摆脱这些

所以你的帖子看起来像这样:

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

答案 1 :(得分:2)

删除散列密钥解析时间表为JSON 不知道这是否是删除哈希键的正确/最佳方法?

      $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);
    });
  }