为什么我不能在`user`上设置对象? - 解析Javascript SDK

时间:2014-07-19 02:18:48

标签: parse-platform

这是我的代码:

  var user = Parse.User.current();

  if (user.isCurrent()) {
    console.log("exports.saveLevel -- isCurrent");
  };


 if (user.authenticated()) {
    console.log("exports.saveLevel -- authenticated");
  };

  var language = req.body.language;
  var level = req.body.level;
  var key = "level_" + language.code;

  console.log("exports.saveLevel -- language.code = " + language.code);
  console.log("exports.saveLevel -- level = " + level);

  // Save the level
  user.set(key, level);

  user.save().then(
    function(obj) {
      console.log("exports.saveLevel -- saved -- obj = " + obj);
      res.send({status: 200});
    },
    function(error) {
      console.log("exports.saveLevel -- error = " + error);
      res.send({status: 500});
    }
  );    

以下是日志。我知道我的所有对象都存在,用户是authenticated

19:16:19 web.1  | exports.saveLevel -- isCurrent
19:16:19 web.1  | exports.saveLevel -- authenticated
19:16:19 web.1  | exports.saveLevel -- langauge = [object Object]
19:16:19 web.1  | exports.saveLevel -- langauge.code = fr
19:16:19 web.1  | exports.saveLevel -- level = [object Object]
19:16:19 web.1  | exports.saveLevel -- level.name = Child
19:16:19 web.1  | POST /saveLevel 500 44ms - 59b

但是我收到500 status code而没有其他错误信息。


以下是console.log(level)的日志:

10:01:08 web.1  | { level: '1',
10:01:08 web.1  |   name: 'Child',
10:01:08 web.1  |   name_en: 'Child',
10:01:08 web.1  |   ACL: 
10:01:08 web.1  |    { '*': { read: 'true' },
10:01:08 web.1  |      'role:Administrators': { write: 'true' },
10:01:08 web.1  |      giLkokRpuK: { write: 'true', read: 'true' } },
10:01:08 web.1  |   objectId: 'b9KaEwoWOV',
10:01:08 web.1  |   createdAt: '2014-04-17T17:41:25.401Z',
10:01:08 web.1  |   updatedAt: '2014-04-23T23:03:43.964Z' }

console.log(language)

10:01:08 web.1  | { code: 'fr',
10:01:08 web.1  |   isSetup: 'true',
10:01:08 web.1  |   name: 'French',
10:01:08 web.1  |   nativeSpelling: 'français',
10:01:08 web.1  |   order: '130',
10:01:08 web.1  |   languageObjectsNative: 
10:01:08 web.1  |    [ { __type: 'Pointer',
10:01:08 web.1  |        className: 'Language',
10:01:08 web.1  |        objectId: 'GQPAHePPl3' } ],
10:01:08 web.1  |   users: { __type: 'Relation', className: '_User' },
10:01:08 web.1  |   usersNative: { __type: 'Relation', className: '_User' },
10:01:08 web.1  |   objectId: 'GQPAHePPl3',
10:01:08 web.1  |   createdAt: '2013-11-15T22:11:16.368Z',
10:01:08 web.1  |   updatedAt: '2014-07-06T03:00:29.380Z' }

1 个答案:

答案 0 :(得分:0)

您必须使用Parse.Cloud.useMasterKey();您可以阅读更多相关信息 here