trixmasta
trixmasta

Reputation: 233

Parse Cloud Code Query keeps coming up as undefined

I'm a swift beginner developer, not really experienced with javascript. I've been trying to make this simple query work for the past few hours, cannot figure out what's wrong.

I want to get the "installationId" attribute of a row in a table called "Post". The row that's selected must match a specific "id".

I've tried so many variations of var a and var b. Like results.get["installationId"] or changing the query to a find() and doing results[0].get["installationId"]. Etc.

Here's my code, and below is the error I record on Parse Cloud.

var postId = request.object.get('postId'); console.log("post id is "+ postId)

   query = new Parse.Query("Post");
   query.equalTo("postId", postId);

   query.first({
    success: function(results) {
       // results is an array of Parse.Object.

       var a = results //.get["installationId"]

       console.log("a query success from cloud code "+a)

       var b = results.object.get["installationId"]

       console.log("b query success from cloud code "+b)

       },

       error: function(error) {
       // error is an instance of Parse.Error.
       console.log("query error from cloud code")
       }
       });

Here's whats returned in the log:

I2015-12-26T08:01:26.373Z] - a query success from cloud code undefined
I2015-12-26T08:01:24.915Z] - post id is 1000
E2015-12-26T08:01:24.881Z] - v12 after_save triggered for AddVote:
  Input: {"object":{"UDID":"[confedential]","createdAt":"2015-12-26T08:01:24.876Z","objectId":"[confedential]","postId":"1000","updatedAt":"2015-12-26T08:01:24.876Z","userId":[confedential]}}
  Result: TypeError: Cannot read property 'get' of undefined
    at e.query.first.success (main.js:26:56)
    at e.<anonymous> (Parse.js:14:28823)
    at e.i (Parse.js:14:27528)
    at e.a.value (Parse.js:14:26888)
    at e.i (Parse.js:14:27655)
    at e.a.value (Parse.js:14:26888)
    at e.i (Parse.js:14:27655)
    at e.a.value (Parse.js:14:26888)
    at e.<anonymous> (Parse.js:14:27599)
    at e.i (Parse.js:14:27528)

Upvotes: 1

Views: 382

Answers (1)

Hardik Shekhat
Hardik Shekhat

Reputation: 1888

Try like below. May be help it.

results[0].get("installationId")

or

var postObj = results[0].toJSON();
var subject = postObj.installationId;

Upvotes: 3

Related Questions