【问题标题】:$$hashKey must not start with '$' Deployd$$hashKey 不能以 '$' 开头
【发布时间】:2015-05-25 22:37:47
【问题描述】:

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

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... 返回一个具有相同值 + 和哈希键的对象

【问题讨论】:

    标签: javascript ionic deployd


    【解决方案1】:

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

    摆脱这些

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

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

    【讨论】:

    • 似乎可以工作,但现在我收到一个新错误对象 {消息:“无法调用未定义的方法 'forEach'”,状态:400} 在我的部署中我得到了 this.timesheets.forEach ... . 在帖子中
    • 您必须在已部署的代码上使用 JSON.parse(this.timesheets) 将 JSON 解码回
    • mm 这给了我 Object {message: "Unexpected token u", status: 400}
    【解决方案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-11-17
      • 2019-05-19
      • 2018-02-22
      • 2017-02-07
      • 1970-01-01
      • 1970-01-01
      • 2012-11-12
      • 2020-10-08
      • 2021-12-20
      相关资源
      最近更新 更多