脚本未将参数加载到数据库中

时间:2018-08-05 18:50:22

标签: javascript database

我的脚本在这里有问题。由于某种原因,它似乎不想连接到数据库中的收藏夹。我遵循了教程,显然我在这里缺少任何人可以建议的东西?我认为这与var StudentsProfileInfo = Collection.createObject(databaseId,...)区域有关,但我不确定,我真的不知道从这里开始。我对代码进行了四倍检查,但我没有找不到任何问题。

// This script requires creating a custom StudentsProfile collection. Then creating
// a 'user_profile' column in Users collection with Pointer type
// referencing StudentsProfile collection.


var databaseId = "5b67344a0f0d31345c60f069";
var username = request.get("username");
var password = request.get("password");
var fullname = request.get("fullname");
var phone = request.get("phone");
var email = request.get("email");
var birthday = request.get("birthday");
var gender = request.get("gender");
var university = request.get("university");
var ra = request.get("ra");
var gpa = request.get("gpa");
var referral = request.get("referral");



try {

  // Register new user
  var userLoginInfo = DatabaseUser.signUp(databaseId, {
    "username": username,
    "password": password
  });


  // Save additonal registration information into 'StudentsProfile' custom collection
  var StudentsProfileInfo = Collection.createObject(databaseId, "StudentsProfile", {
    "fullname": fullname,
    "phone": phone,
    "email": email,
    "birthday": birthday,
    "gender": gender,
    "university": university,
    "ra": ra,
    "gpa": gpa,
    "referral": referral
  }, userLoginInfo.sessionToken);



  // Link Users and StudentsProfile collection
  DatabaseUser.update(databaseId, userLoginInfo._id, {
    "toProfile": {
      "collName": "StudentsProfile",
      "_id": StudentsProfileInfo._id
    }
  }, userLoginInfo.sessionToken);

  // Create a response for this script
  var userData = {
    "session": userLoginInfo.sessionToken,
    "username": username,
    "fullname": fullname,
    "phone": phone,
    "email": email,
    "birthday": birthday,
    "gender": gender,
    "university": university,
    "ra": ra,
    "gpa": gpa,
    "referral": referral
  }

  response.success(userData, "application/json");


} catch (error) {

  response.error({
    "message": "Registration failed. Please try again."
  }, 400);
}

0 个答案:

没有答案