3

嗨,当我发布到已部署时,我在控制台中收到了这个奇怪的错误

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 和签名是一个简单的字符串,timesheets 是一个数组

如果我将 scope.timesheets 替换为

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

有用..

onsole.log(scope.timesheet... 返回具有相同值 + 和哈希键的对象

4

2 回答 2

3

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

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

 dpd.timesheetsdone.post({
  "projectId": $scope.projectId ,
  "formandSig":  $scope.signature,
  "timesheets": angular.toJson($scope.timesheets)
  ...
于 2015-05-25T14:07:08.557 回答
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);
    });
  }
于 2015-05-25T14:37:47.060 回答