简体   繁体   中英

Migrating main.js to Parse Server

I need help migrating my parse server and was directed here by the parse support page.

I have finished the database migration to an mLab database and have the parse server example running in heroku.

My project runs perfectly at retrieving my current data with the default parse server example main.js file, but I would like to still run ParseServer jobs from the client like in this iOS example so I would like to use my own main.js file.

[PFCloud callFunction:@"publishCard" withParameters:@{
@"cardID" : card.cardPF.objectId,
} error:&error];

When I try to run my project with the following file as main.js (I've renamed it newmainjs just for visibility), it doesn't let me login with parse at all anymore from my iOS Client--so it seems to be triggering errors and I have no idea how to debug it as it's not covered in the migration tutorial.

https://github.com/KetchupMoose/cardgameserver/blob/master/cloud/newmain.js

I am very amateur at backend/node so I would really appreciate some support, as I relied on Parse for a lot of things before.

take a look at: https://parse.com/migration

section 3 "cloud code".

You need to change any use of:

Parse.Cloud.useMasterKey()

which you use:

here: https://github.com/KetchupMoose/cardgameserver/blob/master/cloud/newmain.js#L162

and here: https://github.com/KetchupMoose/cardgameserver/blob/master/cloud/newmain.js#L633

instead of using useMasterKey(), you need to pass 'useMasterKey: true' to queries and saves.

Here are a few examples from your code:

userQuery.find({
    useMasterKey: true, // <-- note the addition here
    success: function(results) {
      console.log(results.count);
    ....

And:

}).then(function(saveObjects)
  {
    Parse.Object.saveAll(updatedUserObjects, {
      useMasterKey: true,  // <--- here  
      success: function(list) {
      //assumes all are saved
        response.success("user EloRatings Saved Successfully");
      },
 .....

And:

Parse.Cloud.define("giveSellerGold", function(request, response) {
  Parse.Cloud.useMasterKey();
    var user = new Parse.User();
    var query = new Parse.Query(Parse.User);
    query.equalTo("objectId", request.params.sellerID);
    query.first({
       useMasterKey: true, // <--- here
       success: function(object) {
          object.increment("gold", request.params.sellerGold);
          object.save(null, { useMasterKey: true }); // <-- note how save is done.
          response.success("Successfully saved gold");
       },
       error: function(error) {
        response.error("update failed");
       }
    });
 });

so just make sure that all the queries (that need it) are passing 'useMasterKey' in the options and that ought do it! Good luck.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM