0

So say I do a query on Parse database and get a results object, with each result having a field place_id.

How can I then get a specific object by place_id from the results without actually going back to the database (want to minimise network traffic and db querying...)?

This is what my query will look like:

var LatestUpdate = Parse.Object.extend("LatestUpdate");
var query = new Parse.Query(LatestUpdate);
query.containedIn("place_id", arrayOfplaceIds);
query.find().then(
  function(results){
    // and then i want to do something like:
    return results.findByField("place_id", 1234) // get a specific object from the result without going back to the database?
  }
);

1 Answer 1

1

You have to loop through your results and find the object that matches your criteria. You can do this easily using underscore.js which is supported on the cloud:

var match = _.find(results, function(object){ return object.get("place_id") == 1234; });

Just make sure your have var _ = require('underscore'); on top of your js file.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks - i did end up writing my own function without underscore

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.